| 261 | } |
| 262 | |
| 263 | func deleteRuleCmd(cli *cli) *cobra.Command { |
| 264 | cmd := &cobra.Command{ |
| 265 | Use: "delete", |
| 266 | Aliases: []string{"rm"}, |
| 267 | Short: "Delete a rule", |
| 268 | Long: rulesDeprecationDocumentationText + "Delete a rule.\n\n" + |
| 269 | "To delete interactively, use `auth0 rules delete` with no arguments.\n\n" + |
| 270 | "To delete non-interactively, supply the rule id and the `--force` flag to skip confirmation.", |
| 271 | Example: ` auth0 rules delete |
| 272 | auth0 rules rm |
| 273 | auth0 rules delete <rule-id> |
| 274 | auth0 rules delete <rule-id> --force |
| 275 | auth0 rules delete <rule-id> <rule-id2> <rule-idn> |
| 276 | auth0 rules delete <rule-id> <rule-id2> <rule-idn> --force`, |
| 277 | RunE: func(cmd *cobra.Command, args []string) error { |
| 278 | var ids []string |
| 279 | if len(args) == 0 { |
| 280 | if err := ruleID.PickMany(cmd, &ids, cli.rulePickerOptions); err != nil { |
| 281 | return err |
| 282 | } |
| 283 | } else { |
| 284 | ids = args |
| 285 | } |
| 286 | |
| 287 | if !cli.force && canPrompt(cmd) { |
| 288 | if confirmed := prompt.Confirm("Are you sure you want to proceed?"); !confirmed { |
| 289 | return nil |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | return ansi.ProgressBar("Deleting Rule(s)", ids, func(_ int, id string) error { |
| 294 | if id != "" { |
| 295 | if _, err := cli.api.Rule.Read(cmd.Context(), id); err != nil { |
| 296 | return fmt.Errorf("failed to delete rule with ID %q: %w", id, err) |
| 297 | } |
| 298 | |
| 299 | if err := cli.api.Rule.Delete(cmd.Context(), id); err != nil { |
| 300 | return fmt.Errorf("failed to delete rule with ID %q: %w", id, err) |
| 301 | } |
| 302 | } |
| 303 | return nil |
| 304 | }) |
| 305 | }, |
| 306 | } |
| 307 | |
| 308 | cmd.Flags().BoolVar(&cli.force, "force", false, "Skip confirmation.") |
| 309 | |
| 310 | return cmd |
| 311 | } |
| 312 | |
| 313 | func updateRuleCmd(cli *cli) *cobra.Command { |
| 314 | var inputs struct { |