| 423 | } |
| 424 | |
| 425 | func enableRuleCmd(cli *cli) *cobra.Command { |
| 426 | var inputs struct { |
| 427 | ID string |
| 428 | Enabled bool |
| 429 | } |
| 430 | |
| 431 | cmd := &cobra.Command{ |
| 432 | Use: "enable", |
| 433 | Args: cobra.MaximumNArgs(1), |
| 434 | Short: "Enable a rule", |
| 435 | Long: rulesDeprecationDocumentationText + "Enable a rule.", |
| 436 | Example: ` auth0 rules enable |
| 437 | auth0 rules enable <rule-id> |
| 438 | auth0 rules enable <rule-id> --json |
| 439 | auth0 rules enable <rule-id> --json-compact`, |
| 440 | RunE: func(cmd *cobra.Command, args []string) error { |
| 441 | if len(args) > 0 { |
| 442 | inputs.ID = args[0] |
| 443 | } else { |
| 444 | if err := ruleID.Pick(cmd, &inputs.ID, cli.rulePickerOptions); err != nil { |
| 445 | return err |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | var rule *management.Rule |
| 450 | err := ansi.Waiting(func() error { |
| 451 | var err error |
| 452 | rule, err = cli.api.Rule.Read(cmd.Context(), inputs.ID) |
| 453 | return err |
| 454 | }) |
| 455 | if err != nil { |
| 456 | return fmt.Errorf("failed to fetch rule with ID %q: %w", inputs.ID, err) |
| 457 | } |
| 458 | |
| 459 | rule = &management.Rule{ |
| 460 | Enabled: auth0.Bool(true), |
| 461 | } |
| 462 | |
| 463 | if err = ansi.Waiting(func() error { |
| 464 | return cli.api.Rule.Update(cmd.Context(), inputs.ID, rule) |
| 465 | }); err != nil { |
| 466 | return fmt.Errorf("failed to update rule with ID %q: %w", inputs.ID, err) |
| 467 | } |
| 468 | |
| 469 | cli.renderer.Warnf(rulesDeprecationLogText) |
| 470 | cli.renderer.RuleEnable(rule) |
| 471 | |
| 472 | return nil |
| 473 | }, |
| 474 | } |
| 475 | |
| 476 | cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") |
| 477 | cmd.Flags().BoolVar(&cli.jsonCompact, "json-compact", false, "Output in compact json format.") |
| 478 | |
| 479 | return cmd |
| 480 | } |
| 481 | |
| 482 | func disableRuleCmd(cli *cli) *cobra.Command { |