@@ -21,6 +21,7 @@ import (
21
21
"context"
22
22
"fmt"
23
23
"os"
24
+ "strings"
24
25
25
26
"github.com/arduino/arduino-cli/cli/errorcodes"
26
27
"github.com/arduino/arduino-cli/cli/feedback"
@@ -32,6 +33,7 @@ import (
32
33
33
34
type deleteTagsFlags struct {
34
35
id string
36
+ ids string
35
37
keys []string
36
38
}
37
39
@@ -49,23 +51,48 @@ func InitDeleteTagsCommand() *cobra.Command {
49
51
},
50
52
}
51
53
deleteTagsCommand .Flags ().StringVarP (& flags .id , "id" , "i" , "" , "Device ID" )
54
+ deleteTagsCommand .Flags ().StringVarP (& flags .id , "ids" , "" , "" , "Comma-separated list of Device IDs" )
52
55
deleteTagsCommand .Flags ().StringSliceVarP (& flags .keys , "keys" , "k" , nil , "Comma-separated list of keys of tags to delete" )
53
- deleteTagsCommand .MarkFlagRequired ("id" )
54
56
deleteTagsCommand .MarkFlagRequired ("keys" )
55
57
return deleteTagsCommand
56
58
}
57
59
58
60
func runDeleteTagsCommand (flags * deleteTagsFlags ) error {
59
- logrus .Infof ("Deleting tags with keys %s" , flags .keys )
61
+ if flags .id == "" && flags .ids == "" {
62
+ return fmt .Errorf ("missing required flag(s) \" id\" or \" ids\" " )
63
+ }
64
+
65
+ if flags .id != "" {
66
+ err := deleteTags (flags .id , flags .keys )
67
+ if err != nil {
68
+ return err
69
+ }
70
+ }
71
+ if flags .ids != "" {
72
+ ids := strings .Split (flags .ids , "," )
73
+ for _ , id := range ids {
74
+ id = strings .TrimSpace (id )
75
+ err := deleteTags (id , flags .keys )
76
+ if err != nil {
77
+ return err
78
+ }
79
+ }
80
+ }
81
+
82
+ return nil
83
+ }
84
+
85
+ func deleteTags (id string , keys []string ) error {
86
+ logrus .Infof ("Deleting tags with keys %s" , keys )
60
87
61
88
cred , err := config .RetrieveCredentials ()
62
89
if err != nil {
63
90
return fmt .Errorf ("retrieving credentials: %w" , err )
64
91
}
65
92
66
93
params := & tag.DeleteTagsParams {
67
- ID : flags . id ,
68
- Keys : flags . keys ,
94
+ ID : id ,
95
+ Keys : keys ,
69
96
Resource : tag .Device ,
70
97
}
71
98
0 commit comments