@@ -40,6 +40,7 @@ func initLibCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
4040 }
4141
4242 libCommand .AddCommand (initLibAddCommand (srv ))
43+ libCommand .AddCommand (initLibRemoveCommand (srv ))
4344
4445 return libCommand
4546}
@@ -88,20 +89,80 @@ func runLibAddCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreSer
8889 if err != nil {
8990 feedback .Fatal (i18n .Tr ("Error adding %s to the profile %s: %v" , lib .Name , profileArg .Get (), err ), feedback .ErrGeneric )
9091 }
91- feedback .PrintResult (libResult {LibName : resp .GetLibName (), LibVersion : resp .GetLibVersion (), ProfileName : profileArg .Get ()})
92+ feedback .PrintResult (libAddResult {LibName : resp .GetLibName (), LibVersion : resp .GetLibVersion (), ProfileName : profileArg .Get ()})
9293 }
9394}
9495
95- type libResult struct {
96+ func initLibRemoveCommand (srv rpc.ArduinoCoreServiceServer ) * cobra.Command {
97+ var destDir string
98+
99+ removeCommand := & cobra.Command {
100+ Use : fmt .Sprintf ("remove %s[@%s]..." , i18n .Tr ("LIBRARY" ), i18n .Tr ("VERSION_NUMBER" )),
101+ Short : i18n .Tr ("Removes a library from the profile." ),
102+ Long : i18n .Tr ("Removes a library from the profile." ),
103+ Example : "" +
104+ " " + os .Args [0 ] + " profile lib remove AudioZero -m my_profile\n " +
105+ " " + os .
Args [
0 ]
+ " profile lib remove [email protected] --profile my_profile\n " ,
106+ Args : cobra .MinimumNArgs (1 ),
107+ Run : func (cmd * cobra.Command , args []string ) {
108+ runLibRemoveCommand (cmd .Context (), args , srv , destDir )
109+ },
110+ ValidArgsFunction : func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
111+ return arguments .GetInstallableLibs (cmd .Context (), srv ), cobra .ShellCompDirectiveDefault
112+ },
113+ }
114+
115+ removeCommand .Flags ().StringVar (& destDir , "dest-dir" , "" , i18n .Tr ("Location of the project file." ))
116+ profileArg .AddToCommand (removeCommand , srv )
117+
118+ return removeCommand
119+ }
120+
121+ func runLibRemoveCommand (ctx context.Context , args []string , srv rpc.ArduinoCoreServiceServer , destDir string ) {
122+ sketchPath := arguments .InitSketchPath (destDir )
123+
124+ instance := instance .CreateAndInit (ctx , srv )
125+ libRefs , err := lib .ParseLibraryReferenceArgsAndAdjustCase (ctx , srv , instance , args )
126+ if err != nil {
127+ feedback .Fatal (i18n .Tr ("Arguments error: %v" , err ), feedback .ErrBadArgument )
128+ }
129+ for _ , lib := range libRefs {
130+ resp , err := srv .ProfileLibRemove (ctx , & rpc.ProfileLibRemoveRequest {
131+ SketchPath : sketchPath .String (),
132+ ProfileName : profileArg .Get (),
133+ LibName : lib .Name ,
134+ })
135+ if err != nil {
136+ feedback .Fatal (i18n .Tr ("Error removing %s from the profile %s: %v" , lib .Name , profileArg .Get (), err ), feedback .ErrGeneric )
137+ }
138+ feedback .PrintResult (libRemoveResult {LibName : resp .GetLibName (), LibVersion : resp .GetLibVersion (), ProfileName : profileArg .Get ()})
139+ }
140+ }
141+
142+ type libAddResult struct {
143+ LibName string `json:"library_name"`
144+ LibVersion string `json:"library_version"`
145+ ProfileName string `json:"profile_name"`
146+ }
147+
148+ func (lr libAddResult ) Data () interface {} {
149+ return lr
150+ }
151+
152+ func (lr libAddResult ) String () string {
153+ return i18n .Tr ("Profile %s: %s@%s added successfully" , lr .ProfileName , lr .LibName , lr .LibVersion )
154+ }
155+
156+ type libRemoveResult struct {
96157 LibName string `json:"library_name"`
97158 LibVersion string `json:"library_version"`
98159 ProfileName string `json:"profile_name"`
99160}
100161
101- func (lr libResult ) Data () interface {} {
162+ func (lr libRemoveResult ) Data () interface {} {
102163 return lr
103164}
104165
105- func (lr libResult ) String () string {
106- return i18n .Tr ("Profile %s: %s@%s added succesfully " , lr .ProfileName , lr .LibName , lr .LibVersion )
166+ func (lr libRemoveResult ) String () string {
167+ return i18n .Tr ("Profile %s: %s@%s removed successfully " , lr .ProfileName , lr .LibName , lr .LibVersion )
107168}
0 commit comments