@@ -49,7 +49,8 @@ func initLibCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
49
49
50
50
func initLibAddCommand (srv rpc.ArduinoCoreServiceServer ) * cobra.Command {
51
51
var destDir string
52
-
52
+ var noDeps bool
53
+ var noOverwrite bool
53
54
addCommand := & cobra.Command {
54
55
Use : fmt .Sprintf ("add %s[@%s]..." , i18n .Tr ("LIBRARY" ), i18n .Tr ("VERSION_NUMBER" )),
55
56
Short : i18n .Tr ("Adds a library to the profile." ),
@@ -59,27 +60,31 @@ func initLibAddCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
59
60
" " + os .Args [0 ] + " profile lib add Arduino_JSON@0.2.0 --profile my_profile\n " ,
60
61
Args : cobra .MinimumNArgs (1 ),
61
62
Run : func (cmd * cobra.Command , args []string ) {
62
- runLibAddCommand (cmd .Context (), args , srv , destDir )
63
+ runLibAddCommand (cmd .Context (), args , srv , destDir , noDeps , noOverwrite )
63
64
},
64
65
ValidArgsFunction : func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
65
66
return arguments .GetInstallableLibs (cmd .Context (), srv ), cobra .ShellCompDirectiveDefault
66
67
},
67
68
}
68
69
69
70
addCommand .Flags ().StringVar (& destDir , "dest-dir" , "" , i18n .Tr ("Location of the sketch project file." ))
71
+ addCommand .Flags ().BoolVar (& noDeps , "no-deps" , false , i18n .Tr ("Do not add dependencies." ))
72
+ addCommand .Flags ().BoolVar (& noOverwrite , "no-overwrite" , false , i18n .Tr ("Do not overwrite already added libraries." ))
73
+
70
74
profileArg .AddToCommand (addCommand , srv )
71
75
72
76
return addCommand
73
77
}
74
78
75
- func runLibAddCommand (ctx context.Context , args []string , srv rpc.ArduinoCoreServiceServer , destDir string ) {
79
+ func runLibAddCommand (ctx context.Context , args []string , srv rpc.ArduinoCoreServiceServer , destDir string , noAddDeps , noOverwrite bool ) {
76
80
sketchPath := arguments .InitSketchPath (destDir )
77
81
78
82
instance := instance .CreateAndInit (ctx , srv )
79
83
libRefs , err := lib .ParseLibraryReferenceArgsAndAdjustCase (ctx , srv , instance , args )
80
84
if err != nil {
81
85
feedback .Fatal (i18n .Tr ("Arguments error: %v" , err ), feedback .ErrBadArgument )
82
86
}
87
+ addDeps := ! noAddDeps
83
88
for _ , lib := range libRefs {
84
89
resp , err := srv .ProfileLibAdd (ctx , & rpc.ProfileLibAddRequest {
85
90
Instance : instance ,
@@ -93,16 +98,23 @@ func runLibAddCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreSer
93
98
},
94
99
},
95
100
},
101
+ AddDependencies : & addDeps ,
102
+ NoOverwrite : & noOverwrite ,
96
103
})
97
104
if err != nil {
98
105
feedback .Fatal (i18n .Tr ("Error adding %s to the profile %s: %v" , lib .Name , profileArg .Get (), err ), feedback .ErrGeneric )
99
106
}
100
107
added := f .Map (resp .GetAddedLibraries (), func (l * rpc.ProfileLibraryReference ) * result.ProfileLibraryReference_IndexLibraryResult {
101
108
return result .NewProfileLibraryReference_IndexLibraryResult (l .GetIndexLibrary ())
102
109
})
110
+ skipped := f .Map (resp .GetSkippedLibraries (), func (l * rpc.ProfileLibraryReference ) * result.ProfileLibraryReference_IndexLibraryResult {
111
+ return result .NewProfileLibraryReference_IndexLibraryResult (l .GetIndexLibrary ())
112
+ })
103
113
feedback .PrintResult (libAddResult {
104
- AddedLibraries : added ,
105
- ProfileName : resp .ProfileName })
114
+ AddedLibraries : added ,
115
+ SkippedLibraries : skipped ,
116
+ ProfileName : resp .ProfileName ,
117
+ })
106
118
}
107
119
}
108
120
@@ -179,6 +191,12 @@ func (lr libAddResult) String() string {
179
191
res += fmt .Sprintf (" - %s@%s\n " , l .Name , l .Version )
180
192
}
181
193
}
194
+ if len (lr .SkippedLibraries ) > 0 {
195
+ res += fmt .Sprintln (i18n .Tr ("The following libraries were already present in the profile %s and were not modified:" , lr .ProfileName ))
196
+ for _ , l := range lr .SkippedLibraries {
197
+ res += fmt .Sprintf (" - %s@%s\n " , l .Name , l .Version )
198
+ }
199
+ }
182
200
return res
183
201
}
184
202
0 commit comments