support multiple args for all cscli
upgrade/install/remove commands (#132)
This commit is contained in:
parent
4ef080e7bd
commit
bc2566f3e5
5 changed files with 46 additions and 47 deletions
|
@ -102,7 +102,6 @@ func pullTOP() error {
|
|||
if _, ok := item["scenario"]; !ok {
|
||||
continue
|
||||
}
|
||||
item["scenario"] = fmt.Sprintf("api: %s", item["scenario"])
|
||||
|
||||
if _, ok := item["action"]; !ok {
|
||||
continue
|
||||
|
|
|
@ -71,7 +71,7 @@ you should [update cscli](./cscli_update.md).
|
|||
|
||||
var cmdInstallParser = &cobra.Command{
|
||||
Use: "parser [config]",
|
||||
Short: "Install given log parser",
|
||||
Short: "Install given parser",
|
||||
Long: `Fetch and install given parser from hub`,
|
||||
Example: `cscli install parser crowdsec/xxx`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
|
@ -79,7 +79,9 @@ you should [update cscli](./cscli_update.md).
|
|||
if err := cwhub.GetHubIdx(); err != nil {
|
||||
log.Fatalf("failed to get Hub index : %v", err)
|
||||
}
|
||||
InstallItem(args[0], cwhub.PARSERS)
|
||||
for _, name := range args {
|
||||
InstallItem(name, cwhub.PARSERS)
|
||||
}
|
||||
},
|
||||
}
|
||||
cmdInstall.AddCommand(cmdInstallParser)
|
||||
|
@ -93,7 +95,9 @@ you should [update cscli](./cscli_update.md).
|
|||
if err := cwhub.GetHubIdx(); err != nil {
|
||||
log.Fatalf("failed to get Hub index : %v", err)
|
||||
}
|
||||
InstallItem(args[0], cwhub.SCENARIOS)
|
||||
for _, name := range args {
|
||||
InstallItem(name, cwhub.SCENARIOS)
|
||||
}
|
||||
},
|
||||
}
|
||||
cmdInstall.AddCommand(cmdInstallScenario)
|
||||
|
@ -108,7 +112,9 @@ you should [update cscli](./cscli_update.md).
|
|||
if err := cwhub.GetHubIdx(); err != nil {
|
||||
log.Fatalf("failed to get Hub index : %v", err)
|
||||
}
|
||||
InstallItem(args[0], cwhub.COLLECTIONS)
|
||||
for _, name := range args {
|
||||
InstallItem(name, cwhub.COLLECTIONS)
|
||||
}
|
||||
},
|
||||
}
|
||||
cmdInstall.AddCommand(cmdInstallCollection)
|
||||
|
@ -124,7 +130,9 @@ As a reminder, postoverflows are parsing configuration that will occur after the
|
|||
if err := cwhub.GetHubIdx(); err != nil {
|
||||
log.Fatalf("failed to get Hub index : %v", err)
|
||||
}
|
||||
InstallItem(args[0], cwhub.PARSERS_OVFLW)
|
||||
for _, name := range args {
|
||||
InstallItem(name, cwhub.PARSERS_OVFLW)
|
||||
}
|
||||
},
|
||||
}
|
||||
cmdInstall.AddCommand(cmdInstallPostoverflow)
|
||||
|
|
|
@ -71,15 +71,13 @@ func NewRemoveCmd() *cobra.Command {
|
|||
log.Fatalf("Failed to get Hub index : %v", err)
|
||||
}
|
||||
|
||||
if remove_all && len(args) == 0 {
|
||||
if remove_all {
|
||||
RemoveMany(cwhub.PARSERS, "")
|
||||
} else if len(args) == 1 {
|
||||
RemoveMany(cwhub.PARSERS, args[0])
|
||||
} else {
|
||||
_ = cmd.Help()
|
||||
return
|
||||
for _, name := range args {
|
||||
RemoveMany(cwhub.PARSERS, name)
|
||||
}
|
||||
}
|
||||
//fmt.Println("remove/disable parser: " + strings.Join(args, " "))
|
||||
},
|
||||
}
|
||||
cmdRemove.AddCommand(cmdRemoveParser)
|
||||
|
@ -92,13 +90,12 @@ func NewRemoveCmd() *cobra.Command {
|
|||
if err := cwhub.GetHubIdx(); err != nil {
|
||||
log.Fatalf("Failed to get Hub index : %v", err)
|
||||
}
|
||||
if remove_all && len(args) == 0 {
|
||||
if remove_all {
|
||||
RemoveMany(cwhub.SCENARIOS, "")
|
||||
} else if len(args) == 1 {
|
||||
RemoveMany(cwhub.SCENARIOS, args[0])
|
||||
} else {
|
||||
_ = cmd.Help()
|
||||
return
|
||||
for _, name := range args {
|
||||
RemoveMany(cwhub.SCENARIOS, name)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -112,13 +109,12 @@ func NewRemoveCmd() *cobra.Command {
|
|||
if err := cwhub.GetHubIdx(); err != nil {
|
||||
log.Fatalf("Failed to get Hub index : %v", err)
|
||||
}
|
||||
if remove_all && len(args) == 0 {
|
||||
if remove_all {
|
||||
RemoveMany(cwhub.COLLECTIONS, "")
|
||||
} else if len(args) == 1 {
|
||||
RemoveMany(cwhub.COLLECTIONS, args[0])
|
||||
} else {
|
||||
_ = cmd.Help()
|
||||
return
|
||||
for _, name := range args {
|
||||
RemoveMany(cwhub.COLLECTIONS, name)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -133,13 +129,12 @@ func NewRemoveCmd() *cobra.Command {
|
|||
if err := cwhub.GetHubIdx(); err != nil {
|
||||
log.Fatalf("Failed to get Hub index : %v", err)
|
||||
}
|
||||
if remove_all && len(args) == 0 {
|
||||
if remove_all {
|
||||
RemoveMany(cwhub.PARSERS_OVFLW, "")
|
||||
} else if len(args) == 1 {
|
||||
RemoveMany(cwhub.PARSERS_OVFLW, args[0])
|
||||
} else {
|
||||
_ = cmd.Help()
|
||||
return
|
||||
for _, name := range args {
|
||||
RemoveMany(cwhub.PARSERS_OVFLW, name)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -124,14 +124,14 @@ cscli upgrade --force # Overwrite tainted configuration
|
|||
if err := cwhub.GetHubIdx(); err != nil {
|
||||
log.Fatalf("Failed to get Hub index : %v", err)
|
||||
}
|
||||
if len(args) == 1 {
|
||||
UpgradeConfig(cwhub.PARSERS, args[0])
|
||||
//UpgradeConfig(cwhub.PARSERS_OVFLW, "")
|
||||
} else if upgrade_all {
|
||||
if upgrade_all {
|
||||
UpgradeConfig(cwhub.PARSERS, "")
|
||||
} else {
|
||||
_ = cmd.Help()
|
||||
for _, name := range args {
|
||||
UpgradeConfig(cwhub.PARSERS, name)
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
cmdUpgrade.AddCommand(cmdUpgradeParser)
|
||||
|
@ -146,12 +146,12 @@ cscli upgrade --force # Overwrite tainted configuration
|
|||
if err := cwhub.GetHubIdx(); err != nil {
|
||||
log.Fatalf("Failed to get Hub index : %v", err)
|
||||
}
|
||||
if len(args) == 1 {
|
||||
UpgradeConfig(cwhub.SCENARIOS, args[0])
|
||||
} else if upgrade_all {
|
||||
if upgrade_all {
|
||||
UpgradeConfig(cwhub.SCENARIOS, "")
|
||||
} else {
|
||||
_ = cmd.Help()
|
||||
for _, name := range args {
|
||||
UpgradeConfig(cwhub.SCENARIOS, name)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -168,12 +168,12 @@ cscli upgrade --force # Overwrite tainted configuration
|
|||
if err := cwhub.GetHubIdx(); err != nil {
|
||||
log.Fatalf("Failed to get Hub index : %v", err)
|
||||
}
|
||||
if len(args) == 1 {
|
||||
UpgradeConfig(cwhub.COLLECTIONS, args[0])
|
||||
} else if upgrade_all {
|
||||
if upgrade_all {
|
||||
UpgradeConfig(cwhub.COLLECTIONS, "")
|
||||
} else {
|
||||
_ = cmd.Help()
|
||||
for _, name := range args {
|
||||
UpgradeConfig(cwhub.COLLECTIONS, name)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -191,12 +191,12 @@ cscli upgrade --force # Overwrite tainted configuration
|
|||
if err := cwhub.GetHubIdx(); err != nil {
|
||||
log.Fatalf("Failed to get Hub index : %v", err)
|
||||
}
|
||||
if len(args) == 1 {
|
||||
UpgradeConfig(cwhub.PARSERS_OVFLW, args[0])
|
||||
} else if upgrade_all {
|
||||
if upgrade_all {
|
||||
UpgradeConfig(cwhub.PARSERS_OVFLW, "")
|
||||
} else {
|
||||
_ = cmd.Help()
|
||||
for _, name := range args {
|
||||
UpgradeConfig(cwhub.PARSERS_OVFLW, name)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -813,9 +813,6 @@ func HubStatus(itype string, name string, list_all bool) []map[string]string {
|
|||
log.Errorf("type %s doesn't exist", itype)
|
||||
return nil
|
||||
}
|
||||
if list_all {
|
||||
log.Printf("only enabled ones")
|
||||
}
|
||||
|
||||
var mli []map[string]string
|
||||
/*remember, you do it for the user :)*/
|
||||
|
|
Loading…
Reference in a new issue