@@ -24,6 +24,7 @@ import (
2424 "github.com/arduino/arduino-cli/cli/instance"
2525 "github.com/arduino/arduino-cli/cli/output"
2626 "github.com/arduino/arduino-cli/commands/lib"
27+ "github.com/arduino/arduino-cli/configuration"
2728 rpc "github.com/arduino/arduino-cli/rpc/commands"
2829 "github.com/spf13/cobra"
2930)
@@ -40,8 +41,10 @@ func initInstallCommand() *cobra.Command {
4041 Run : runInstallCommand ,
4142 }
4243 installCommand .Flags ().BoolVar (& installFlags .noDeps , "no-deps" , false , "Do not install dependencies." )
43- installCommand .Flags ().BoolVar (& installFlags .gitURL , "git-url" , false , "Enter git url for libraries hosted on repositories" )
44- installCommand .Flags ().BoolVar (& installFlags .zipPath , "zip-path" , false , "Enter a path to zip file" )
44+ if configuration .Settings .GetBool ("library.enable_unsafe_install" ) {
45+ installCommand .Flags ().BoolVar (& installFlags .gitURL , "git-url" , false , "Enter git url for libraries hosted on repositories" )
46+ installCommand .Flags ().BoolVar (& installFlags .zipPath , "zip-path" , false , "Enter a path to zip file" )
47+ }
4548 return installCommand
4649}
4750
@@ -53,6 +56,11 @@ var installFlags struct {
5356
5457func runInstallCommand (cmd * cobra.Command , args []string ) {
5558 instance := instance .CreateInstanceIgnorePlatformIndexErrors ()
59+
60+ if installFlags .zipPath || installFlags .gitURL {
61+ feedback .Print ("--git-url and --zip-path flags are dangerous, use it at your own risk." )
62+ }
63+
5664 if installFlags .zipPath {
5765 ziplibraryInstallReq := & rpc.ZipLibraryInstallReq {
5866 Instance : instance ,
@@ -63,7 +71,10 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
6371 feedback .Errorf ("Error installing Zip Library: %v" , err )
6472 os .Exit (errorcodes .ErrGeneric )
6573 }
66- } else if installFlags .gitURL {
74+ return
75+ }
76+
77+ if installFlags .gitURL {
6778 gitlibraryInstallReq := & rpc.GitLibraryInstallReq {
6879 Instance : instance ,
6980 Url : args [0 ],
@@ -73,58 +84,59 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
7384 feedback .Errorf ("Error installing Git Library: %v" , err )
7485 os .Exit (errorcodes .ErrGeneric )
7586 }
76- } else {
77- libRefs , err := ParseLibraryReferenceArgsAndAdjustCase (instance , args )
78- if err != nil {
79- feedback .Errorf ("Arguments error: %v" , err )
80- os .Exit (errorcodes .ErrBadArgument )
81- }
87+ return
88+ }
8289
83- toInstall := map [string ]* rpc.LibraryDependencyStatus {}
84- if installFlags .noDeps {
85- for _ , libRef := range libRefs {
86- toInstall [libRef .Name ] = & rpc.LibraryDependencyStatus {
87- Name : libRef .Name ,
88- VersionRequired : libRef .Version ,
89- }
90- }
91- } else {
92- for _ , libRef := range libRefs {
93- depsResp , err := lib .LibraryResolveDependencies (context .Background (), & rpc.LibraryResolveDependenciesReq {
94- Instance : instance ,
95- Name : libRef .Name ,
96- Version : libRef .Version ,
97- })
98- if err != nil {
99- feedback .Errorf ("Error resolving dependencies for %s: %s" , libRef , err )
100- os .Exit (errorcodes .ErrGeneric )
101- }
102- for _ , dep := range depsResp .GetDependencies () {
103- feedback .Printf ("%s depends on %s@%s" , libRef , dep .GetName (), dep .GetVersionRequired ())
104- if existingDep , has := toInstall [dep .GetName ()]; has {
105- if existingDep .GetVersionRequired () != dep .GetVersionRequired () {
106- // TODO: make a better error
107- feedback .Errorf ("The library %s is required in two different versions: %s and %s" ,
108- dep .GetName (), dep .GetVersionRequired (), existingDep .GetVersionRequired ())
109- os .Exit (errorcodes .ErrGeneric )
110- }
111- }
112- toInstall [dep .GetName ()] = dep
113- }
90+ libRefs , err := ParseLibraryReferenceArgsAndAdjustCase (instance , args )
91+ if err != nil {
92+ feedback .Errorf ("Arguments error: %v" , err )
93+ os .Exit (errorcodes .ErrBadArgument )
94+ }
95+
96+ toInstall := map [string ]* rpc.LibraryDependencyStatus {}
97+ if installFlags .noDeps {
98+ for _ , libRef := range libRefs {
99+ toInstall [libRef .Name ] = & rpc.LibraryDependencyStatus {
100+ Name : libRef .Name ,
101+ VersionRequired : libRef .Version ,
114102 }
115103 }
116-
117- for _ , library := range toInstall {
118- libraryInstallReq := & rpc.LibraryInstallReq {
104+ } else {
105+ for _ , libRef := range libRefs {
106+ depsResp , err := lib . LibraryResolveDependencies ( context . Background (), & rpc.LibraryResolveDependenciesReq {
119107 Instance : instance ,
120- Name : library .Name ,
121- Version : library .VersionRequired ,
122- }
123- err := lib .LibraryInstall (context .Background (), libraryInstallReq , output .ProgressBar (), output .TaskProgress ())
108+ Name : libRef .Name ,
109+ Version : libRef .Version ,
110+ })
124111 if err != nil {
125- feedback .Errorf ("Error installing %s: %v " , library , err )
112+ feedback .Errorf ("Error resolving dependencies for %s: %s " , libRef , err )
126113 os .Exit (errorcodes .ErrGeneric )
127114 }
115+ for _ , dep := range depsResp .GetDependencies () {
116+ feedback .Printf ("%s depends on %s@%s" , libRef , dep .GetName (), dep .GetVersionRequired ())
117+ if existingDep , has := toInstall [dep .GetName ()]; has {
118+ if existingDep .GetVersionRequired () != dep .GetVersionRequired () {
119+ // TODO: make a better error
120+ feedback .Errorf ("The library %s is required in two different versions: %s and %s" ,
121+ dep .GetName (), dep .GetVersionRequired (), existingDep .GetVersionRequired ())
122+ os .Exit (errorcodes .ErrGeneric )
123+ }
124+ }
125+ toInstall [dep .GetName ()] = dep
126+ }
127+ }
128+ }
129+
130+ for _ , library := range toInstall {
131+ libraryInstallReq := & rpc.LibraryInstallReq {
132+ Instance : instance ,
133+ Name : library .Name ,
134+ Version : library .VersionRequired ,
135+ }
136+ err := lib .LibraryInstall (context .Background (), libraryInstallReq , output .ProgressBar (), output .TaskProgress ())
137+ if err != nil {
138+ feedback .Errorf ("Error installing %s: %v" , library , err )
139+ os .Exit (errorcodes .ErrGeneric )
128140 }
129141 }
130142}
0 commit comments