@@ -49,7 +49,8 @@ func initLibCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
4949
5050func initLibAddCommand (srv rpc.ArduinoCoreServiceServer )* cobra.Command {
5151var destDir string
52-
52+ var noDeps bool
53+ var noOverwrite bool
5354addCommand := & cobra.Command {
5455Use :fmt .Sprintf ("add %s[@%s]..." ,i18n .Tr ("LIBRARY" ),i18n .Tr ("VERSION_NUMBER" )),
5556Short :i18n .Tr ("Adds a library to the profile." ),
@@ -59,27 +60,31 @@ func initLibAddCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
5960" " + os .Args [0 ]+ " profile lib add Arduino_JSON@0.2.0 --profile my_profile\n " ,
6061Args :cobra .MinimumNArgs (1 ),
6162Run :func (cmd * cobra.Command ,args []string ) {
62- runLibAddCommand (cmd .Context (),args ,srv ,destDir )
63+ runLibAddCommand (cmd .Context (),args ,srv ,destDir , noDeps , noOverwrite )
6364},
6465ValidArgsFunction :func (cmd * cobra.Command ,args []string ,toComplete string ) ([]string , cobra.ShellCompDirective ) {
6566return arguments .GetInstallableLibs (cmd .Context (),srv ),cobra .ShellCompDirectiveDefault
6667},
6768}
6869
6970addCommand .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+
7074profileArg .AddToCommand (addCommand ,srv )
7175
7276return addCommand
7377}
7478
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 ) {
7680sketchPath := arguments .InitSketchPath (destDir )
7781
7882instance := instance .CreateAndInit (ctx ,srv )
7983libRefs ,err := lib .ParseLibraryReferenceArgsAndAdjustCase (ctx ,srv ,instance ,args )
8084if err != nil {
8185feedback .Fatal (i18n .Tr ("Arguments error: %v" ,err ),feedback .ErrBadArgument )
8286}
87+ addDeps := ! noAddDeps
8388for _ ,lib := range libRefs {
8489resp ,err := srv .ProfileLibAdd (ctx ,& rpc.ProfileLibAddRequest {
8590Instance :instance ,
@@ -93,16 +98,23 @@ func runLibAddCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreSer
9398},
9499},
95100},
101+ AddDependencies :& addDeps ,
102+ NoOverwrite :& noOverwrite ,
96103})
97104if err != nil {
98105feedback .Fatal (i18n .Tr ("Error adding %s to the profile %s: %v" ,lib .Name ,profileArg .Get (),err ),feedback .ErrGeneric )
99106}
100107added := f .Map (resp .GetAddedLibraries (),func (l * rpc.ProfileLibraryReference )* result.ProfileLibraryReference_IndexLibraryResult {
101108return result .NewProfileLibraryReference_IndexLibraryResult (l .GetIndexLibrary ())
102109})
110+ skipped := f .Map (resp .GetSkippedLibraries (),func (l * rpc.ProfileLibraryReference )* result.ProfileLibraryReference_IndexLibraryResult {
111+ return result .NewProfileLibraryReference_IndexLibraryResult (l .GetIndexLibrary ())
112+ })
103113feedback .PrintResult (libAddResult {
104- AddedLibraries :added ,
105- ProfileName :resp .ProfileName })
114+ AddedLibraries :added ,
115+ SkippedLibraries :skipped ,
116+ ProfileName :resp .ProfileName ,
117+ })
106118}
107119}
108120
@@ -179,6 +191,12 @@ func (lr libAddResult) String() string {
179191res += fmt .Sprintf (" - %s@%s\n " ,l .Name ,l .Version )
180192}
181193}
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+ }
182200return res
183201}
184202