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