Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[A0CLI-27] feat: Delete a rule by specifying an ID #33

Merged
merged 2 commits into from
Jan 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}