Skip to content

Commit

Permalink
Merge pull request #33 from auth0/add/delete-rule
Browse files Browse the repository at this point in the history
[A0CLI-27] feat: Delete a rule by specifying an ID
  • Loading branch information
Alexis Kulash authored Jan 26, 2021
2 parents dcb3f06 + ad6379f commit d3c341c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions internal/cli/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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().StringVar(&flags.id, "id", "", "ID of the rule to delete (required)")

return cmd
}

0 comments on commit d3c341c

Please sign in to comment.