(cli *cli)
| 311 | } |
| 312 | |
| 313 | func 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( |
no test coverage detected