diff --git a/internal/cli/actions.go b/internal/cli/actions.go index d95b75868..db9158177 100644 --- a/internal/cli/actions.go +++ b/internal/cli/actions.go @@ -310,11 +310,20 @@ func updateActionCmd(cli *cli) *cobra.Command { &inputs.Code, oldAction.GetCode(), inputs.Name+".*.js", - cli.actionEditorHint, ); err != nil { return fmt.Errorf("failed to capture input from the editor: %w", err) } + if !cli.force && canPrompt(cmd) { + var confirmed bool + if err := prompt.AskBool("Do you want to save the action code?", &confirmed, true); err != nil { + return fmt.Errorf("failed to capture prompt input: %w", err) + } + if !confirmed { + return nil + } + } + updatedAction := &management.Action{ SupportedTriggers: oldAction.SupportedTriggers, } @@ -344,6 +353,7 @@ func updateActionCmd(cli *cli) *cobra.Command { } cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") + cmd.Flags().BoolVar(&cli.force, "force", false, "Skip confirmation.") actionName.RegisterStringU(cmd, &inputs.Name, "") actionCode.RegisterStringU(cmd, &inputs.Code, "") actionDependency.RegisterStringMapU(cmd, &inputs.Dependencies, nil) diff --git a/internal/cli/email_templates.go b/internal/cli/email_templates.go index 7146a13eb..5b7e7781d 100644 --- a/internal/cli/email_templates.go +++ b/internal/cli/email_templates.go @@ -7,6 +7,7 @@ import ( "github.com/spf13/cobra" "github.com/auth0/auth0-cli/internal/ansi" + "github.com/auth0/auth0-cli/internal/prompt" ) const ( @@ -211,11 +212,20 @@ func updateEmailTemplateCmd(cli *cli) *cobra.Command { &inputs.Body, oldTemplate.GetBody(), inputs.Template+".*.liquid", - cli.emailTemplateEditorHint, ); err != nil { return fmt.Errorf("failed to capture input from the editor: %w", err) } + if !cli.force && canPrompt(cmd) { + var confirmed bool + if err := prompt.AskBool("Do you want to save the email template body?", &confirmed, true); err != nil { + return fmt.Errorf("failed to capture prompt input: %w", err) + } + if !confirmed { + return nil + } + } + if err := emailTemplateEnabled.AskBoolU(cmd, &inputs.Enabled, oldTemplate.Enabled); err != nil { return err } @@ -254,6 +264,7 @@ func updateEmailTemplateCmd(cli *cli) *cobra.Command { } cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") + cmd.Flags().BoolVar(&cli.force, "force", false, "Skip confirmation.") emailTemplateBody.RegisterStringU(cmd, &inputs.Body, "") emailTemplateFrom.RegisterStringU(cmd, &inputs.From, "") emailTemplateSubject.RegisterStringU(cmd, &inputs.Subject, "") @@ -264,10 +275,6 @@ func updateEmailTemplateCmd(cli *cli) *cobra.Command { return cmd } -func (c *cli) emailTemplateEditorHint() { - c.renderer.Infof("%s Once you close the editor, the email template will be saved. To cancel, press CTRL+C.", ansi.Faint("Hint:")) -} - func (c *cli) emailTemplatePickerOptions() (pickerOptions, error) { return emailTemplateOptions, nil } diff --git a/internal/cli/flags.go b/internal/cli/flags.go index 23f8985df..08837f1c9 100644 --- a/internal/cli/flags.go +++ b/internal/cli/flags.go @@ -94,7 +94,7 @@ func (f *Flag) OpenEditorW(cmd *cobra.Command, value *string, defaultValue, file return openEditorFlag(cmd, f, value, defaultValue, filename, infoFn, tempFileFn, false) } -func (f *Flag) OpenEditorU(cmd *cobra.Command, value *string, defaultValue string, filename string, infoFn func()) error { +func (f *Flag) OpenEditorU(cmd *cobra.Command, value *string, defaultValue string, filename string) error { return openEditorFlag(cmd, f, value, defaultValue, filename, nil, nil, true) } diff --git a/internal/cli/rules.go b/internal/cli/rules.go index a7e91ff04..fde793d52 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -352,12 +352,21 @@ func updateRuleCmd(cli *cli) *cobra.Command { &inputs.Script, oldRule.GetScript(), oldRule.GetName()+".*.js", - cli.ruleEditorHint, ) if err != nil { return fmt.Errorf("failed to capture input from the editor: %w", err) } + if !cli.force && canPrompt(cmd) { + var confirmed bool + if err := prompt.AskBool("Do you want to save the rule script?", &confirmed, true); err != nil { + return fmt.Errorf("failed to capture prompt input: %w", err) + } + if !confirmed { + return nil + } + } + updatedRule.Enabled = &inputs.Enabled if inputs.Name != "" { updatedRule.Name = &inputs.Name @@ -381,6 +390,7 @@ func updateRuleCmd(cli *cli) *cobra.Command { } cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") + cmd.Flags().BoolVar(&cli.force, "force", false, "Skip confirmation.") ruleName.RegisterStringU(cmd, &inputs.Name, "") ruleEnabled.RegisterBool(cmd, &inputs.Enabled, true) ruleScript.RegisterStringU(cmd, &inputs.Script, "")