| 480 | } |
| 481 | |
| 482 | func disableRuleCmd(cli *cli) *cobra.Command { |
| 483 | var inputs struct { |
| 484 | ID string |
| 485 | Enabled bool |
| 486 | } |
| 487 | |
| 488 | cmd := &cobra.Command{ |
| 489 | Use: "disable", |
| 490 | Args: cobra.MaximumNArgs(1), |
| 491 | Short: "Disable a rule", |
| 492 | Long: rulesDeprecationDocumentationText + "Disable a rule.", |
| 493 | Example: ` auth0 rules disable |
| 494 | auth0 rules disable <rule-id> |
| 495 | auth0 rules disable <rule-id> --json |
| 496 | auth0 rules disable <rule-id> --json-compact`, |
| 497 | RunE: func(cmd *cobra.Command, args []string) error { |
| 498 | if len(args) > 0 { |
| 499 | inputs.ID = args[0] |
| 500 | } else { |
| 501 | if err := ruleID.Pick(cmd, &inputs.ID, cli.rulePickerOptions); err != nil { |
| 502 | return err |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | var rule *management.Rule |
| 507 | err := ansi.Waiting(func() (err error) { |
| 508 | rule, err = cli.api.Rule.Read(cmd.Context(), inputs.ID) |
| 509 | return err |
| 510 | }) |
| 511 | if err != nil { |
| 512 | return fmt.Errorf("failed to fetch rule with ID %q: %w", inputs.ID, err) |
| 513 | } |
| 514 | |
| 515 | rule = &management.Rule{ |
| 516 | Enabled: auth0.Bool(false), |
| 517 | } |
| 518 | |
| 519 | if err = ansi.Waiting(func() error { |
| 520 | return cli.api.Rule.Update(cmd.Context(), inputs.ID, rule) |
| 521 | }); err != nil { |
| 522 | return fmt.Errorf("failed to update rule with ID %q: %w", inputs.ID, err) |
| 523 | } |
| 524 | |
| 525 | cli.renderer.RuleDisable(rule) |
| 526 | cli.renderer.Warnf(rulesDeprecationLogText) |
| 527 | |
| 528 | return nil |
| 529 | }, |
| 530 | } |
| 531 | |
| 532 | cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") |
| 533 | cmd.Flags().BoolVar(&cli.jsonCompact, "json-compact", false, "Output in compact json format.") |
| 534 | |
| 535 | return cmd |
| 536 | } |
| 537 | |
| 538 | func (c *cli) rulePickerOptions(ctx context.Context) (pickerOptions, error) { |
| 539 | list, err := c.api.Rule.List(ctx) |