@@ -35,6 +35,7 @@ func initLibAddCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
3535 var destDir string
3636 var noDeps bool
3737 var noOverwrite bool
38+ var profileArg arguments.Profile
3839 addCommand := & cobra.Command {
3940 Use : fmt .Sprintf ("add %s[@%s]..." , i18n .Tr ("LIBRARY" ), i18n .Tr ("VERSION_NUMBER" )),
4041 Short : i18n .Tr ("Adds a library to a sketch profile." ),
@@ -43,23 +44,20 @@ func initLibAddCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
4344 " " + os .
Args [
0 ]
+ " profile lib add [email protected] --profile my_profile\n " ,
4445 Args : cobra .MinimumNArgs (1 ),
4546 Run : func (cmd * cobra.Command , args []string ) {
46- runLibAddCommand (cmd .Context (), args , srv , destDir , noDeps , noOverwrite )
47+ runLibAddCommand (cmd .Context (), args , srv , profileArg . Get (), destDir , noDeps , noOverwrite )
4748 },
4849 ValidArgsFunction : func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
4950 return arguments .GetInstallableLibs (cmd .Context (), srv ), cobra .ShellCompDirectiveDefault
5051 },
5152 }
52-
53+ profileArg . AddToCommand ( addCommand , srv )
5354 addCommand .Flags ().StringVar (& destDir , "dest-dir" , "" , i18n .Tr ("Location of the sketch project file." ))
5455 addCommand .Flags ().BoolVar (& noDeps , "no-deps" , false , i18n .Tr ("Do not add dependencies." ))
5556 addCommand .Flags ().BoolVar (& noOverwrite , "no-overwrite" , false , i18n .Tr ("Do not overwrite already added libraries." ))
56-
57- profileArg .AddToCommand (addCommand , srv )
58-
5957 return addCommand
6058}
6159
62- func runLibAddCommand (ctx context.Context , args []string , srv rpc.ArduinoCoreServiceServer , destDir string , noAddDeps , noOverwrite bool ) {
60+ func runLibAddCommand (ctx context.Context , args []string , srv rpc.ArduinoCoreServiceServer , profile , destDir string , noAddDeps , noOverwrite bool ) {
6361 sketchPath := arguments .InitSketchPath (destDir )
6462
6563 instance := instance .CreateAndInit (ctx , srv )
@@ -72,7 +70,7 @@ func runLibAddCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreSer
7270 resp , err := srv .ProfileLibAdd (ctx , & rpc.ProfileLibAddRequest {
7371 Instance : instance ,
7472 SketchPath : sketchPath .String (),
75- ProfileName : profileArg . Get () ,
73+ ProfileName : profile ,
7674 Library : & rpc.ProfileLibraryReference {
7775 Library : & rpc.ProfileLibraryReference_IndexLibrary_ {
7876 IndexLibrary : & rpc.ProfileLibraryReference_IndexLibrary {
@@ -85,7 +83,7 @@ func runLibAddCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreSer
8583 NoOverwrite : & noOverwrite ,
8684 })
8785 if err != nil {
88- feedback .Fatal (i18n .Tr ("Error adding %s to the profile %s: %v" , lib .Name , profileArg . Get () , err ), feedback .ErrGeneric )
86+ feedback .Fatal (i18n .Tr ("Error adding %s to the profile %s: %v" , lib .Name , profile , err ), feedback .ErrGeneric )
8987 }
9088 feedback .PrintResult (libAddResult {
9189 AddedLibraries : f .Map (resp .GetAddedLibraries (), result .NewProfileLibraryReference ),
0 commit comments