Skip to content

Commit

Permalink
Use a constant error for prompts that do not have forced values.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-as committed Nov 21, 2024
1 parent fa5bc02 commit 40b37ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions internal/captain/rationalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/prompt"
"github.com/ActiveState/cli/internal/runbits/rationalize"
"github.com/ActiveState/cli/pkg/buildscript"
"github.com/ActiveState/cli/pkg/localcommit"
Expand Down Expand Up @@ -38,5 +39,10 @@ func rationalizeError(err *error) {
*err = errs.WrapUserFacing(*err,
locale.T("err_outdated_buildscript"),
errs.SetInput())

case errors.Is(*err, prompt.ErrNoForceOption):
*err = errs.WrapUserFacing(*err,
locale.T("err_prompt_no_force_option",
"This command has a prompt that does not support the '[ACTIONABLE]--force[/RESET]' flag."))
}
}
8 changes: 5 additions & 3 deletions internal/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type Prompt struct {
isForced bool
}

var ErrNoForceOption = errs.New("No force option given for forced prompt")

// New creates a new prompter
func New(out output.Outputer, an EventDispatcher) Prompter {
return &Prompt{out, an, out.Config().Interactive, false}
Expand Down Expand Up @@ -113,7 +115,7 @@ func (p *Prompt) InputAndValidate(title, message string, defaultResponse *string
p.out.Notice(locale.Tr("prompt_using_force", *response))
return *response, nil
}
return "", errs.New("No force option given for forced prompt")
return "", ErrNoForceOption
}

if !p.isInteractive {
Expand Down Expand Up @@ -172,7 +174,7 @@ func (p *Prompt) Select(title, message string, choices []string, defaultChoice *
p.out.Notice(locale.Tr("prompt_using_force", *choice))
return *choice, nil
}
return "", errs.New("No force option given for forced prompt")
return "", ErrNoForceOption
}

if !p.isInteractive {
Expand Down Expand Up @@ -218,7 +220,7 @@ func (p *Prompt) Confirm(title, message string, defaultChoice *bool, forcedChoic
p.out.Notice(locale.T("prompt_continue_force"))
return *choice, nil
}
return false, errs.New("No force option given for forced prompt")
return false, ErrNoForceOption
}

if !p.isInteractive {
Expand Down

0 comments on commit 40b37ba

Please sign in to comment.