From 6147b84f945eb72e752695eb61738c95fc8c468d Mon Sep 17 00:00:00 2001 From: Prasanth Vaaheeswaran Date: Mon, 25 Jan 2021 13:30:26 -0500 Subject: [PATCH 01/12] feat: add enable/disable rules support to cli --- internal/cli/rules.go | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index f3bb6bce3..609886962 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -1,9 +1,15 @@ package cli import ( + "errors" + "fmt" + "github.com/spf13/cobra" + "gopkg.in/auth0.v5/management" ) +var rules []string + func rulesCmd(cli *cli) *cobra.Command { cmd := &cobra.Command{ Use: "rules", @@ -12,6 +18,8 @@ func rulesCmd(cli *cli) *cobra.Command { cmd.SetUsageTemplate(resourceUsageTemplate()) cmd.AddCommand(listRulesCmd(cli)) + cmd.AddCommand(enableRuleCmd(cli)) + cmd.AddCommand(disableRuleCmd(cli)) return cmd } @@ -34,3 +42,55 @@ func listRulesCmd(cli *cli) *cobra.Command { return cmd } + +func enableRuleCmd(cli *cli) *cobra.Command { + cmd := &cobra.Command{ + Use: "enable", + Short: "enable rule", + PreRunE: func(cmd *cobra.Command, args []string) error { + if len(rules) == 0 { + return errors.New("No rules to process") + } + return nil + }, + RunE: func(cmd *cobra.Command, args []string) error { + fmt.Printf("Got following rules:\n%s\n", rules) + + enable := true + err := cli.api.Client.Rule.Update(rules[0], &management.Rule{Enabled: &enable}) + + if err != nil { + return err + } + + return nil + }, + } + + cmd.Flags().StringArrayVarP(&rules, "rules", "r", nil, "rule ids") + cmd.MarkFlagRequired("rules") + + return cmd +} + +func disableRuleCmd(cli *cli) *cobra.Command { + cmd := &cobra.Command{ + Use: "disable", + Short: "disable rule", + PreRunE: func(cmd *cobra.Command, args []string) error { + fmt.Printf("in prerun, %d", len(rules)) + if len(rules) == 0 { + fmt.Print("rules empty") + return errors.New("no rules to process") + } + return nil + }, + RunE: func(cmd *cobra.Command, args []string) error { + return nil + }, + } + + cmd.Flags().StringArrayVarP(&rules, "rules", "r", nil, "rule ids") + + return cmd +} From 21a480d8bbbeaa0f75fbf4673583e6400bf5dd99 Mon Sep 17 00:00:00 2001 From: Prasanth Vaaheeswaran Date: Mon, 25 Jan 2021 14:47:55 -0500 Subject: [PATCH 02/12] chore: wire up update/disable logic --- internal/auth/auth.go | 2 +- internal/cli/rules.go | 91 ++++++++++++++++++++++++++++++++++++----- internal/rules/rules.go | 1 + 3 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 internal/rules/rules.go diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 0e74768a4..77271ce0c 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -33,7 +33,7 @@ const ( deviceCodeEndpoint = "https://auth0.auth0.com/oauth/device/code" oauthTokenEndpoint = "https://auth0.auth0.com/oauth/token" // TODO(jfatta) extend the scope as we extend the CLI: - scope = "openid read:roles read:clients read:logs read:rules" + scope = "openid read:roles read:clients read:logs read:rules update:rules delete:rules create:rules" audiencePath = "/api/v2/" ) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index 609886962..e91a9cc4e 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -46,7 +46,7 @@ func listRulesCmd(cli *cli) *cobra.Command { func enableRuleCmd(cli *cli) *cobra.Command { cmd := &cobra.Command{ Use: "enable", - Short: "enable rule", + Short: "enable rule(s)", PreRunE: func(cmd *cobra.Command, args []string) error { if len(rules) == 0 { return errors.New("No rules to process") @@ -54,21 +54,33 @@ func enableRuleCmd(cli *cli) *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { - fmt.Printf("Got following rules:\n%s\n", rules) + // fmt.Printf("Got following rules (%d):\n%s\n", len(rules), rules) + + // @TODO Cleanup error handling, some can pass some can fail + updateErrors := enableRules(rules, cli.api.Client.Rule) + if updateErrors != nil { + for _, err := range updateErrors { + fmt.Println(err) + } + return errors.New("Some rule updates failed") + } - enable := true - err := cli.api.Client.Rule.Update(rules[0], &management.Rule{Enabled: &enable}) + // @TODO Only display modified rules + rules, err := cli.api.Client.Rule.List() if err != nil { return err } + cli.renderer.RulesList(rules) + return nil }, } - cmd.Flags().StringArrayVarP(&rules, "rules", "r", nil, "rule ids") - cmd.MarkFlagRequired("rules") + cmd.Flags().StringSliceVarP(&rules, "rules", "r", nil, "rule ids") + // @TODO Take a look at this later + // err := cmd.MarkFlagRequired("rules") return cmd } @@ -76,21 +88,78 @@ func enableRuleCmd(cli *cli) *cobra.Command { func disableRuleCmd(cli *cli) *cobra.Command { cmd := &cobra.Command{ Use: "disable", - Short: "disable rule", + Short: "disable rule(s)", PreRunE: func(cmd *cobra.Command, args []string) error { - fmt.Printf("in prerun, %d", len(rules)) if len(rules) == 0 { - fmt.Print("rules empty") - return errors.New("no rules to process") + return errors.New("No rules to process") } return nil }, RunE: func(cmd *cobra.Command, args []string) error { + // fmt.Printf("Got following rules (%d):\n%s\n", len(rules), rules) + + // @TODO Cleanup error handling, some can pass some can fail + updateErrors := disableRules(rules, cli.api.Client.Rule) + if updateErrors != nil { + for _, err := range updateErrors { + fmt.Println(err) + } + return errors.New("Some rule updates failed") + } + + // @TODO Only display modified rules + rules, err := cli.api.Client.Rule.List() + + if err != nil { + return err + } + + cli.renderer.RulesList(rules) + return nil }, } - cmd.Flags().StringArrayVarP(&rules, "rules", "r", nil, "rule ids") + cmd.Flags().StringSliceVarP(&rules, "rules", "r", nil, "rule ids") + // @TODO Take a look at this later + // err := cmd.MarkFlagRequired("rules") return cmd } + +// @TODO refactor to rules package +// @TODO can probably run these concurrently + +func enableRules(ruleIds []string, ruleManager *management.RuleManager) []error { + var updateErrors []error + enable := true + for _, ruleID := range ruleIds { + err := ruleManager.Update(ruleID, &management.Rule{Enabled: &enable}) + if err != nil { + updateErrors = append(updateErrors, err) + } + } + + if len(updateErrors) != 0 { + return updateErrors + } + + return nil +} + +func disableRules(ruleIds []string, ruleManager *management.RuleManager) []error { + var updateErrors []error + enable := false + for _, ruleID := range ruleIds { + err := ruleManager.Update(ruleID, &management.Rule{Enabled: &enable}) + if err != nil { + updateErrors = append(updateErrors, err) + } + } + + if len(updateErrors) != 0 { + return updateErrors + } + + return nil +} diff --git a/internal/rules/rules.go b/internal/rules/rules.go new file mode 100644 index 000000000..1e8c7fa08 --- /dev/null +++ b/internal/rules/rules.go @@ -0,0 +1 @@ +package rules From 2db40924f7e6265098a1a97faf2c3fd01f51d0ed Mon Sep 17 00:00:00 2001 From: Prasanth Vaaheeswaran Date: Mon, 25 Jan 2021 17:53:33 -0500 Subject: [PATCH 03/12] refactor: update command to meet rules spec --- internal/cli/rules.go | 108 +++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index e91a9cc4e..f31b76396 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -5,10 +5,11 @@ import ( "fmt" "github.com/spf13/cobra" + "gopkg.in/auth0.v5" "gopkg.in/auth0.v5/management" ) -var rules []string +var name string func rulesCmd(cli *cli) *cobra.Command { cmd := &cobra.Command{ @@ -29,7 +30,7 @@ func listRulesCmd(cli *cli) *cobra.Command { Short: "Lists your rules", Long: `Lists the rules in your current tenant.`, RunE: func(cmd *cobra.Command, args []string) error { - rules, err := cli.api.Client.Rule.List() + rules, err := getRules(cli) if err != nil { return err @@ -48,25 +49,29 @@ func enableRuleCmd(cli *cli) *cobra.Command { Use: "enable", Short: "enable rule(s)", PreRunE: func(cmd *cobra.Command, args []string) error { - if len(rules) == 0 { + if name == "" { return errors.New("No rules to process") } return nil }, RunE: func(cmd *cobra.Command, args []string) error { - // fmt.Printf("Got following rules (%d):\n%s\n", len(rules), rules) + data, err := getRules(cli) + if err != nil { + return err + } - // @TODO Cleanup error handling, some can pass some can fail - updateErrors := enableRules(rules, cli.api.Client.Rule) - if updateErrors != nil { - for _, err := range updateErrors { - fmt.Println(err) + ruleExists, ruleIdx := findRuleByName(name, data.Rules) + if ruleExists { + err := enableRule(data.Rules[ruleIdx], cli) + if err != nil { + return err } - return errors.New("Some rule updates failed") + } else { + return fmt.Errorf("No rule found with name: \"%s\"", name) } // @TODO Only display modified rules - rules, err := cli.api.Client.Rule.List() + rules, err := getRules(cli) if err != nil { return err @@ -78,9 +83,9 @@ func enableRuleCmd(cli *cli) *cobra.Command { }, } - cmd.Flags().StringSliceVarP(&rules, "rules", "r", nil, "rule ids") + cmd.Flags().StringVarP(&name, "name", "n", "", "rule name") // @TODO Take a look at this later - // err := cmd.MarkFlagRequired("rules") + // cmd.MarkFlagRequired("rules") return cmd } @@ -88,27 +93,31 @@ func enableRuleCmd(cli *cli) *cobra.Command { func disableRuleCmd(cli *cli) *cobra.Command { cmd := &cobra.Command{ Use: "disable", - Short: "disable rule(s)", + Short: "disable rule", PreRunE: func(cmd *cobra.Command, args []string) error { - if len(rules) == 0 { + if name == "" { return errors.New("No rules to process") } return nil }, RunE: func(cmd *cobra.Command, args []string) error { - // fmt.Printf("Got following rules (%d):\n%s\n", len(rules), rules) + data, err := getRules(cli) + if err != nil { + return err + } - // @TODO Cleanup error handling, some can pass some can fail - updateErrors := disableRules(rules, cli.api.Client.Rule) - if updateErrors != nil { - for _, err := range updateErrors { - fmt.Println(err) + ruleExists, ruleIdx := findRuleByName(name, data.Rules) + if ruleExists { + err := disableRule(data.Rules[ruleIdx], cli) + if err != nil { + return err } - return errors.New("Some rule updates failed") + } else { + return fmt.Errorf("No rule found with name: \"%s\"", name) } // @TODO Only display modified rules - rules, err := cli.api.Client.Rule.List() + rules, err := getRules(cli) if err != nil { return err @@ -120,46 +129,35 @@ func disableRuleCmd(cli *cli) *cobra.Command { }, } - cmd.Flags().StringSliceVarP(&rules, "rules", "r", nil, "rule ids") + cmd.Flags().StringVarP(&name, "name", "n", "", "rule name") // @TODO Take a look at this later - // err := cmd.MarkFlagRequired("rules") + // cmd.MarkFlagRequired("rules") return cmd } - -// @TODO refactor to rules package -// @TODO can probably run these concurrently - -func enableRules(ruleIds []string, ruleManager *management.RuleManager) []error { - var updateErrors []error - enable := true - for _, ruleID := range ruleIds { - err := ruleManager.Update(ruleID, &management.Rule{Enabled: &enable}) - if err != nil { - updateErrors = append(updateErrors, err) - } - } - - if len(updateErrors) != 0 { - return updateErrors - } - - return nil +func getRules(cli *cli) (list *management.RuleList, err error) { + list, err = cli.api.Client.Rule.List() + return } -func disableRules(ruleIds []string, ruleManager *management.RuleManager) []error { - var updateErrors []error - enable := false - for _, ruleID := range ruleIds { - err := ruleManager.Update(ruleID, &management.Rule{Enabled: &enable}) - if err != nil { - updateErrors = append(updateErrors, err) +func findRuleByName(name string, rules []*management.Rule) (exists bool, idx int) { + exists = false + for i, aRule := range rules { + if (*aRule.Name) == name { + exists = true + idx = i + break } } + return +} - if len(updateErrors) != 0 { - return updateErrors - } +func enableRule(rule *management.Rule, cli *cli) (err error) { + err = cli.api.Client.Rule.Update(rule.GetID(), &management.Rule{Enabled: auth0.Bool(true)}) + return +} - return nil +func disableRule(rule *management.Rule, cli *cli) (err error) { + err = cli.api.Client.Rule.Update(rule.GetID(), &management.Rule{Enabled: auth0.Bool(false)}) + return } From ff41f82eb5f74173546ce37e920a910a2feaf18d Mon Sep 17 00:00:00 2001 From: Prasanth Vaaheeswaran Date: Mon, 25 Jan 2021 18:00:33 -0500 Subject: [PATCH 04/12] chore: comments --- internal/cli/rules.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index f31b76396..3c815c137 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -85,7 +85,7 @@ func enableRuleCmd(cli *cli) *cobra.Command { cmd.Flags().StringVarP(&name, "name", "n", "", "rule name") // @TODO Take a look at this later - // cmd.MarkFlagRequired("rules") + // cmd.MarkFlagRequired("name") return cmd } @@ -131,10 +131,12 @@ func disableRuleCmd(cli *cli) *cobra.Command { cmd.Flags().StringVarP(&name, "name", "n", "", "rule name") // @TODO Take a look at this later - // cmd.MarkFlagRequired("rules") + // cmd.MarkFlagRequired("name") return cmd } + +// @TODO move to rules package func getRules(cli *cli) (list *management.RuleList, err error) { list, err = cli.api.Client.Rule.List() return From 89e9443826820ce616a9205bbea2061a949d1688 Mon Sep 17 00:00:00 2001 From: Prasanth Vaaheeswaran Date: Mon, 25 Jan 2021 19:01:25 -0500 Subject: [PATCH 05/12] chore: address change requests --- internal/cli/rules.go | 47 ++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index 3c815c137..6aa5257f2 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -9,8 +9,6 @@ import ( "gopkg.in/auth0.v5/management" ) -var name string - func rulesCmd(cli *cli) *cobra.Command { cmd := &cobra.Command{ Use: "rules", @@ -45,6 +43,7 @@ func listRulesCmd(cli *cli) *cobra.Command { } func enableRuleCmd(cli *cli) *cobra.Command { + var name string cmd := &cobra.Command{ Use: "enable", Short: "enable rule(s)", @@ -60,9 +59,9 @@ func enableRuleCmd(cli *cli) *cobra.Command { return err } - ruleExists, ruleIdx := findRuleByName(name, data.Rules) - if ruleExists { - err := enableRule(data.Rules[ruleIdx], cli) + rule := findRuleByName(name, data.Rules) + if rule != nil { + err := enableRule(rule, cli) if err != nil { return err } @@ -84,13 +83,12 @@ func enableRuleCmd(cli *cli) *cobra.Command { } cmd.Flags().StringVarP(&name, "name", "n", "", "rule name") - // @TODO Take a look at this later - // cmd.MarkFlagRequired("name") - + cmd.MarkPersistentFlagRequired("name") return cmd } func disableRuleCmd(cli *cli) *cobra.Command { + var name string cmd := &cobra.Command{ Use: "disable", Short: "disable rule", @@ -106,9 +104,9 @@ func disableRuleCmd(cli *cli) *cobra.Command { return err } - ruleExists, ruleIdx := findRuleByName(name, data.Rules) - if ruleExists { - err := disableRule(data.Rules[ruleIdx], cli) + rule := findRuleByName(name, data.Rules) + if rule != nil { + err := disableRule(rule, cli) if err != nil { return err } @@ -130,36 +128,31 @@ func disableRuleCmd(cli *cli) *cobra.Command { } cmd.Flags().StringVarP(&name, "name", "n", "", "rule name") - // @TODO Take a look at this later - // cmd.MarkFlagRequired("name") + cmd.MarkPersistentFlagRequired("name") return cmd } // @TODO move to rules package func getRules(cli *cli) (list *management.RuleList, err error) { - list, err = cli.api.Client.Rule.List() - return + return cli.api.Client.Rule.List() } -func findRuleByName(name string, rules []*management.Rule) (exists bool, idx int) { - exists = false - for i, aRule := range rules { +func findRuleByName(name string, rules []*management.Rule) *management.Rule { + var foundRule *management.Rule + for _, aRule := range rules { if (*aRule.Name) == name { - exists = true - idx = i + foundRule = aRule break } } - return + return foundRule } -func enableRule(rule *management.Rule, cli *cli) (err error) { - err = cli.api.Client.Rule.Update(rule.GetID(), &management.Rule{Enabled: auth0.Bool(true)}) - return +func enableRule(rule *management.Rule, cli *cli) error { + return cli.api.Client.Rule.Update(rule.GetID(), &management.Rule{Enabled: auth0.Bool(true)}) } -func disableRule(rule *management.Rule, cli *cli) (err error) { - err = cli.api.Client.Rule.Update(rule.GetID(), &management.Rule{Enabled: auth0.Bool(false)}) - return +func disableRule(rule *management.Rule, cli *cli) error { + return cli.api.Client.Rule.Update(rule.GetID(), &management.Rule{Enabled: auth0.Bool(false)}) } From 33aa3e98a25813626e5c162703fb5579903fbdcf Mon Sep 17 00:00:00 2001 From: Prasanth Vaaheeswaran Date: Mon, 25 Jan 2021 19:18:39 -0500 Subject: [PATCH 06/12] Update internal/cli/rules.go Co-authored-by: Cyril David --- internal/cli/rules.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index 6aa5257f2..039597edb 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -66,7 +66,7 @@ func enableRuleCmd(cli *cli) *cobra.Command { return err } } else { - return fmt.Errorf("No rule found with name: \"%s\"", name) + return fmt.Errorf("No rule found with name: %q", name) } // @TODO Only display modified rules From 669a69f4f8056bccc07cdbf1e9d9aa30a9812ce3 Mon Sep 17 00:00:00 2001 From: Prasanth Vaaheeswaran Date: Mon, 25 Jan 2021 19:19:12 -0500 Subject: [PATCH 07/12] Update internal/cli/rules.go Co-authored-by: Cyril David --- internal/cli/rules.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index 039597edb..88ca249e6 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -106,8 +106,7 @@ func disableRuleCmd(cli *cli) *cobra.Command { rule := findRuleByName(name, data.Rules) if rule != nil { - err := disableRule(rule, cli) - if err != nil { + if err := disableRule(rule, cli); err != nil { return err } } else { From 8cc91c108c36a72055b88561e49ac3d6dd889c7d Mon Sep 17 00:00:00 2001 From: Prasanth Vaaheeswaran Date: Mon, 25 Jan 2021 19:19:21 -0500 Subject: [PATCH 08/12] Update internal/cli/rules.go Co-authored-by: Cyril David --- internal/cli/rules.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index 88ca249e6..01c673d2a 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -110,7 +110,7 @@ func disableRuleCmd(cli *cli) *cobra.Command { return err } } else { - return fmt.Errorf("No rule found with name: \"%s\"", name) + return fmt.Errorf("No rule found with name: %q", name) } // @TODO Only display modified rules From e4baad8b0d65325abca9cbaf37569505b2156041 Mon Sep 17 00:00:00 2001 From: Prasanth Vaaheeswaran Date: Mon, 25 Jan 2021 19:21:39 -0500 Subject: [PATCH 09/12] Update internal/cli/rules.go Co-authored-by: Cyril David --- internal/cli/rules.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index 01c673d2a..828c58eee 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -127,7 +127,7 @@ func disableRuleCmd(cli *cli) *cobra.Command { } cmd.Flags().StringVarP(&name, "name", "n", "", "rule name") - cmd.MarkPersistentFlagRequired("name") + mustRequireFlags(cmd, "name") return cmd } From 894882995637f20c2c1ccd14414ee52b8a49e6e2 Mon Sep 17 00:00:00 2001 From: Prasanth Vaaheeswaran Date: Mon, 25 Jan 2021 19:22:11 -0500 Subject: [PATCH 10/12] Update internal/cli/rules.go Co-authored-by: Cyril David --- internal/cli/rules.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index 828c58eee..4bb56d17b 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -138,14 +138,12 @@ func getRules(cli *cli) (list *management.RuleList, err error) { } func findRuleByName(name string, rules []*management.Rule) *management.Rule { - var foundRule *management.Rule - for _, aRule := range rules { - if (*aRule.Name) == name { - foundRule = aRule - break + for _, r := range rules { + if auth0.StringValue(r.Name) == name { + return r } } - return foundRule + return nil } func enableRule(rule *management.Rule, cli *cli) error { From 6c3ce1ece8fb8b9eb360b14db1dc8e3aca9fa437 Mon Sep 17 00:00:00 2001 From: Prasanth Vaaheeswaran Date: Mon, 25 Jan 2021 19:22:26 -0500 Subject: [PATCH 11/12] Update internal/cli/rules.go Co-authored-by: Cyril David --- internal/cli/rules.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index 4bb56d17b..04490fcc2 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -83,7 +83,7 @@ func enableRuleCmd(cli *cli) *cobra.Command { } cmd.Flags().StringVarP(&name, "name", "n", "", "rule name") - cmd.MarkPersistentFlagRequired("name") + mustRequireFlags(cmd, "name") return cmd } From 7df72dd0e4cf73450019b43e32c0d03b63c00311 Mon Sep 17 00:00:00 2001 From: Prasanth Vaaheeswaran Date: Mon, 25 Jan 2021 19:26:46 -0500 Subject: [PATCH 12/12] refactor: remove prerun --- internal/cli/rules.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index 04490fcc2..ad90c8893 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -1,7 +1,6 @@ package cli import ( - "errors" "fmt" "github.com/spf13/cobra" @@ -47,12 +46,6 @@ func enableRuleCmd(cli *cli) *cobra.Command { cmd := &cobra.Command{ Use: "enable", Short: "enable rule(s)", - PreRunE: func(cmd *cobra.Command, args []string) error { - if name == "" { - return errors.New("No rules to process") - } - return nil - }, RunE: func(cmd *cobra.Command, args []string) error { data, err := getRules(cli) if err != nil { @@ -92,12 +85,6 @@ func disableRuleCmd(cli *cli) *cobra.Command { cmd := &cobra.Command{ Use: "disable", Short: "disable rule", - PreRunE: func(cmd *cobra.Command, args []string) error { - if name == "" { - return errors.New("No rules to process") - } - return nil - }, RunE: func(cmd *cobra.Command, args []string) error { data, err := getRules(cli) if err != nil {