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 1 commit
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().StringVarP(&flags.id, "id", "i", "", "ID of the rule to delete (required)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if not having a short form given id is already super short is fine here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about that... "id" wasn't accepted as that param, so I suppose I just need to leave it as an empty string and perhaps that'll omit the short form? 🤞


return cmd
}