Print y/n options when displaying prompts using cmdio.Ask (#650)

## Changes
Adds `[y/n]` in `cmdio.Ask` to make the options obvious in all question
prompts

## Tests
Test manually. Works.
This commit is contained in:
shreyas-goenka 2023-08-09 11:22:42 +02:00 committed by GitHub
parent 54a1bcd10a
commit 6430d23453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 2 deletions

View File

@ -27,7 +27,7 @@ func (m *delete) Apply(ctx context.Context, b *bundle.Bundle) error {
red := color.New(color.FgRed).SprintFunc()
if !b.AutoApprove {
proceed, err := cmdio.Ask(ctx, fmt.Sprintf("\n%s and all files in it will be %s Proceed?: ", b.Config.Workspace.RootPath, red("deleted permanently!")))
proceed, err := cmdio.Ask(ctx, fmt.Sprintf("\n%s and all files in it will be %s Proceed?", b.Config.Workspace.RootPath, red("deleted permanently!")))
if err != nil {
return err
}

View File

@ -89,7 +89,7 @@ func (w *destroy) Apply(ctx context.Context, b *bundle.Bundle) error {
// Ask for confirmation, if needed
if !b.Plan.ConfirmApply {
red := color.New(color.FgRed).SprintFunc()
b.Plan.ConfirmApply, err = cmdio.Ask(ctx, fmt.Sprintf("\nThis will permanently %s resources! Proceed? [y/n]: ", red("destroy")))
b.Plan.ConfirmApply, err = cmdio.Ask(ctx, fmt.Sprintf("\nThis will permanently %s resources! Proceed?", red("destroy")))
if err != nil {
return err
}

View File

@ -87,6 +87,8 @@ func (l *Logger) Ask(question string) (bool, error) {
return false, fmt.Errorf("question prompts are not supported in json mode")
}
// Add acceptable answers to the question prompt.
question += ` [y/n]:`
l.Writer.Write([]byte(question))
ans, err := l.Reader.ReadString('\n')