From d433a42c2ece078daa5db08e9abcda86e7e59f42 Mon Sep 17 00:00:00 2001 From: Alexis Kulash Date: Mon, 25 Jan 2021 19:17:59 -0500 Subject: [PATCH 1/2] Adding basic functionality for deleting rules by specifying an ID --- internal/cli/rules.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index 813feb1e7..9ad57ae66 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -15,6 +15,7 @@ func rulesCmd(cli *cli) *cobra.Command { cmd.SetUsageTemplate(resourceUsageTemplate()) cmd.AddCommand(listRulesCmd(cli)) cmd.AddCommand(createRulesCmd(cli)) + cmd.AddCommand(deleteRulesCmd(cli)) return cmd } @@ -82,3 +83,37 @@ func createRulesCmd(cli *cli) *cobra.Command { return cmd } + +func deleteRulesCmd(cli *cli) *cobra.Command { + var flags struct { + id string + } + + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete a rule", + Long: `Delete a rule: + + auth0 rules delete --id "12345"`, + RunE: func(cmd *cobra.Command, args []string) error { + r := &management.Rule{ID: &flags.id} + + // TODO: Should add validation of rule + // TODO: Would be nice to prompt user confirmation before proceeding with delete + + err := ansi.Spinner("Deleting rule", func() error { + return cli.api.Client.Rule.Delete(*r.ID) + }) + + if err != nil { + return err + } + + return nil + }, + } + + cmd.Flags().StringVarP(&flags.id, "id", "i", "", "ID of the rule to delete (required)") + + return cmd +} From ad6379ff96ce8e715538582d57918b45897da43b Mon Sep 17 00:00:00 2001 From: Alexis Kulash Date: Mon, 25 Jan 2021 19:38:14 -0500 Subject: [PATCH 2/2] Removing unnecessary short shorthand and refactoring var type --- internal/cli/rules.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index 9ad57ae66..364d39173 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -97,7 +97,7 @@ func deleteRulesCmd(cli *cli) *cobra.Command { auth0 rules delete --id "12345"`, RunE: func(cmd *cobra.Command, args []string) error { r := &management.Rule{ID: &flags.id} - + // TODO: Should add validation of rule // TODO: Would be nice to prompt user confirmation before proceeding with delete @@ -113,7 +113,7 @@ func deleteRulesCmd(cli *cli) *cobra.Command { }, } - cmd.Flags().StringVarP(&flags.id, "id", "i", "", "ID of the rule to delete (required)") + cmd.Flags().StringVar(&flags.id, "id", "", "ID of the rule to delete (required)") return cmd }