|
@@ -67,26 +67,30 @@ func NewCollectionsCmd() *cobra.Command {
|
|
Short: "Remove given collection(s)",
|
|
Short: "Remove given collection(s)",
|
|
Long: `Remove given collection(s) from hub`,
|
|
Long: `Remove given collection(s) from hub`,
|
|
Example: `cscli collections remove crowdsec/xxx crowdsec/xyz`,
|
|
Example: `cscli collections remove crowdsec/xxx crowdsec/xyz`,
|
|
- Args: cobra.MinimumNArgs(1),
|
|
|
|
DisableAutoGenTag: true,
|
|
DisableAutoGenTag: true,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
if all {
|
|
if all {
|
|
RemoveMany(cwhub.COLLECTIONS, "")
|
|
RemoveMany(cwhub.COLLECTIONS, "")
|
|
- } else {
|
|
|
|
- for _, name := range args {
|
|
|
|
- if !forceAction {
|
|
|
|
- item := cwhub.GetItem(cwhub.COLLECTIONS, name)
|
|
|
|
- if item == nil {
|
|
|
|
- log.Fatalf("unable to retrieve: %s\n", name)
|
|
|
|
- }
|
|
|
|
- if len(item.BelongsToCollections) > 0 {
|
|
|
|
- log.Warningf("%s belongs to other collections :\n%s\n", name, item.BelongsToCollections)
|
|
|
|
- log.Printf("Run 'sudo cscli collections remove %s --force' if you want to force remove this sub collection\n", name)
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if len(args) == 0 {
|
|
|
|
+ log.Fatalf("Specify at least one collection to remove or '--all' flag.")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for _, name := range args {
|
|
|
|
+ if !forceAction {
|
|
|
|
+ item := cwhub.GetItem(cwhub.COLLECTIONS, name)
|
|
|
|
+ if item == nil {
|
|
|
|
+ log.Fatalf("unable to retrieve: %s\n", name)
|
|
|
|
+ }
|
|
|
|
+ if len(item.BelongsToCollections) > 0 {
|
|
|
|
+ log.Warningf("%s belongs to other collections :\n%s\n", name, item.BelongsToCollections)
|
|
|
|
+ log.Printf("Run 'sudo cscli collections remove %s --force' if you want to force remove this sub collection\n", name)
|
|
|
|
+ continue
|
|
}
|
|
}
|
|
- RemoveMany(cwhub.COLLECTIONS, name)
|
|
|
|
}
|
|
}
|
|
|
|
+ RemoveMany(cwhub.COLLECTIONS, name)
|
|
}
|
|
}
|
|
},
|
|
},
|
|
}
|
|
}
|