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

Function updateRuleCmd

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

Source from the content-addressed store, hash-verified

311}
312
313func updateRuleCmd(cli *cli) *cobra.Command {
314 var inputs struct {
315 ID string
316 Name string
317 Script string
318 Enabled bool
319 }
320
321 cmd := &cobra.Command{
322 Use: "update",
323 Args: cobra.MaximumNArgs(1),
324 Short: "Update a rule",
325 Long: rulesDeprecationDocumentationText + "Update a rule.\n\n" +
326 "To update interactively, use `auth0 rules update` with no arguments.\n\n" +
327 "To update non-interactively, supply the rule id and other information through the flags.",
328 Example: ` auth0 rules update <id>
329 auth0 rules update <rule-id> --enabled=true
330 auth0 rules update <rule-id> --enabled=false --name "My Updated Rule"
331 auth0 rules update <rule-id> --enabled=true --name "My Updated Rule" --script "$(cat path/to/script.js)"
332 auth0 rules update <rule-id> -e=true -n "My Updated Rule" -s "$(cat path/to/script.js)" --json
333 auth0 rules update <rule-id> -e=true -n "My Updated Rule" -s "$(cat path/to/script.js)" --json-compact
334 echo "{\"id\":\"rul_ks3dUazcU3b6PqkH\",\"name\":\"piping-name\"}" | auth0 rules update`,
335 RunE: func(cmd *cobra.Command, args []string) error {
336 updatedRule := &management.Rule{}
337 pipedInput := iostream.PipedInput()
338 if len(pipedInput) > 0 {
339 if err := json.Unmarshal(pipedInput, updatedRule); err != nil {
340 return fmt.Errorf("invalid JSON input: %w", err)
341 }
342
343 inputs.ID = updatedRule.GetID()
344 updatedRule.ID = nil
345 } else {
346 if len(args) > 0 {
347 inputs.ID = args[0]
348 } else {
349 if err := ruleID.Pick(cmd, &inputs.ID, cli.rulePickerOptions); err != nil {
350 return err
351 }
352 }
353
354 var oldRule *management.Rule
355 err := ansi.Waiting(func() (err error) {
356 oldRule, err = cli.api.Rule.Read(cmd.Context(), inputs.ID)
357 return err
358 })
359 if err != nil {
360 return fmt.Errorf("failed to fetch rule with ID %q: %w", inputs.ID, err)
361 }
362
363 if err := ruleName.AskU(cmd, &inputs.Name, oldRule.Name); err != nil {
364 return err
365 }
366 if err := ruleEnabled.AskBoolU(cmd, &inputs.Enabled, oldRule.Enabled); err != nil {
367 return err
368 }
369
370 err = ruleScript.OpenEditorU(

Callers 1

rulesCmdFunction · 0.85

Calls 15

PipedInputFunction · 0.92
WaitingFunction · 0.92
AskBoolFunction · 0.92
canPromptFunction · 0.85
noLocalFlagSetFunction · 0.85
ErrorfMethod · 0.80
AskUMethod · 0.80
AskBoolUMethod · 0.80
OpenEditorUMethod · 0.80
IsSetMethod · 0.80
WarnfMethod · 0.80
RuleUpdateMethod · 0.80

Tested by

no test coverage detected