@@ -24,6 +24,7 @@ import (
24
24
"github.com/arduino/arduino-cli/cli/instance"
25
25
"github.com/arduino/arduino-cli/cli/output"
26
26
"github.com/arduino/arduino-cli/commands/lib"
27
+ "github.com/arduino/arduino-cli/configuration"
27
28
rpc "github.com/arduino/arduino-cli/rpc/commands"
28
29
"github.com/spf13/cobra"
29
30
)
@@ -40,8 +41,10 @@ func initInstallCommand() *cobra.Command {
40
41
Run : runInstallCommand ,
41
42
}
42
43
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
+ }
45
48
return installCommand
46
49
}
47
50
@@ -53,6 +56,11 @@ var installFlags struct {
53
56
54
57
func runInstallCommand (cmd * cobra.Command , args []string ) {
55
58
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
+
56
64
if installFlags .zipPath {
57
65
ziplibraryInstallReq := & rpc.ZipLibraryInstallReq {
58
66
Instance : instance ,
@@ -63,7 +71,10 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
63
71
feedback .Errorf ("Error installing Zip Library: %v" , err )
64
72
os .Exit (errorcodes .ErrGeneric )
65
73
}
66
- } else if installFlags .gitURL {
74
+ return
75
+ }
76
+
77
+ if installFlags .gitURL {
67
78
gitlibraryInstallReq := & rpc.GitLibraryInstallReq {
68
79
Instance : instance ,
69
80
Url : args [0 ],
@@ -73,58 +84,59 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
73
84
feedback .Errorf ("Error installing Git Library: %v" , err )
74
85
os .Exit (errorcodes .ErrGeneric )
75
86
}
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
+ }
82
89
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 ,
114
102
}
115
103
}
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 {
119
107
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
+ })
124
111
if err != nil {
125
- feedback .Errorf ("Error installing %s: %v " , library , err )
112
+ feedback .Errorf ("Error resolving dependencies for %s: %s " , libRef , err )
126
113
os .Exit (errorcodes .ErrGeneric )
127
114
}
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 )
128
140
}
129
141
}
130
142
}
0 commit comments