MCPcopy Create free account
hub / github.com/auth0/auth0-cli / disableRuleCmd

Function disableRuleCmd

internal/cli/rules.go:482–536  ·  view source on GitHub ↗
(cli *cli)

Source from the content-addressed store, hash-verified

480}
481
482func 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
538func (c *cli) rulePickerOptions(ctx context.Context) (pickerOptions, error) {
539 list, err := c.api.Rule.List(ctx)

Callers 1

rulesCmdFunction · 0.85

Calls 7

WaitingFunction · 0.92
ErrorfMethod · 0.80
RuleDisableMethod · 0.80
WarnfMethod · 0.80
ReadMethod · 0.65
UpdateMethod · 0.65
PickMethod · 0.45

Tested by

no test coverage detected