Skip to content

Commit 40b37ba

Browse files
committed
Use a constant error for prompts that do not have forced values.
1 parent fa5bc02 commit 40b37ba

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

internal/captain/rationalize.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/ActiveState/cli/internal/errs"
77
"github.com/ActiveState/cli/internal/locale"
8+
"github.com/ActiveState/cli/internal/prompt"
89
"github.com/ActiveState/cli/internal/runbits/rationalize"
910
"github.com/ActiveState/cli/pkg/buildscript"
1011
"github.com/ActiveState/cli/pkg/localcommit"
@@ -38,5 +39,10 @@ func rationalizeError(err *error) {
3839
*err = errs.WrapUserFacing(*err,
3940
locale.T("err_outdated_buildscript"),
4041
errs.SetInput())
42+
43+
case errors.Is(*err, prompt.ErrNoForceOption):
44+
*err = errs.WrapUserFacing(*err,
45+
locale.T("err_prompt_no_force_option",
46+
"This command has a prompt that does not support the '[ACTIONABLE]--force[/RESET]' flag."))
4147
}
4248
}

internal/prompt/prompt.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ type Prompt struct {
4545
isForced bool
4646
}
4747

48+
var ErrNoForceOption = errs.New("No force option given for forced prompt")
49+
4850
// New creates a new prompter
4951
func New(out output.Outputer, an EventDispatcher) Prompter {
5052
return &Prompt{out, an, out.Config().Interactive, false}
@@ -113,7 +115,7 @@ func (p *Prompt) InputAndValidate(title, message string, defaultResponse *string
113115
p.out.Notice(locale.Tr("prompt_using_force", *response))
114116
return *response, nil
115117
}
116-
return "", errs.New("No force option given for forced prompt")
118+
return "", ErrNoForceOption
117119
}
118120

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

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

224226
if !p.isInteractive {

0 commit comments

Comments
 (0)