From 04298e40b075f670e8d2738b89f3d87d2e25f612 Mon Sep 17 00:00:00 2001 From: monalisa Date: Wed, 9 Aug 2023 01:08:50 +0200 Subject: [PATCH 1/2] Add y/n options for file deletion prompt --- bundle/deploy/files/delete.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/deploy/files/delete.go b/bundle/deploy/files/delete.go index 1f103bbd06..37ac0597aa 100644 --- a/bundle/deploy/files/delete.go +++ b/bundle/deploy/files/delete.go @@ -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? [y/n]: ", b.Config.Workspace.RootPath, red("deleted permanently!"))) if err != nil { return err } From 7a00eb99f9affe11166c30f2878fc34581abed70 Mon Sep 17 00:00:00 2001 From: monalisa Date: Wed, 9 Aug 2023 11:14:58 +0200 Subject: [PATCH 2/2] add prompts in ask function --- bundle/deploy/files/delete.go | 2 +- bundle/deploy/terraform/destroy.go | 2 +- libs/cmdio/logger.go | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bundle/deploy/files/delete.go b/bundle/deploy/files/delete.go index 37ac0597aa..990eca47a7 100644 --- a/bundle/deploy/files/delete.go +++ b/bundle/deploy/files/delete.go @@ -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? [y/n]: ", 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 } diff --git a/bundle/deploy/terraform/destroy.go b/bundle/deploy/terraform/destroy.go index 839ea5f9ce..649542f6f2 100644 --- a/bundle/deploy/terraform/destroy.go +++ b/bundle/deploy/terraform/destroy.go @@ -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 } diff --git a/libs/cmdio/logger.go b/libs/cmdio/logger.go index a507c5cce7..3190a6a797 100644 --- a/libs/cmdio/logger.go +++ b/libs/cmdio/logger.go @@ -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')