aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/cli/cmd/root.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/go/internal/cli/cmd/root.go')
-rw-r--r--client/go/internal/cli/cmd/root.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/client/go/internal/cli/cmd/root.go b/client/go/internal/cli/cmd/root.go
index 17c4fc41625..89184e7a7fa 100644
--- a/client/go/internal/cli/cmd/root.go
+++ b/client/go/internal/cli/cmd/root.go
@@ -301,6 +301,26 @@ func (c *CLI) printWarning(msg interface{}, hints ...string) {
}
}
+func (c *CLI) confirm(question string) (bool, error) {
+ if !c.isTerminal() {
+ return false, fmt.Errorf("terminal is not interactive")
+ }
+ for {
+ var answer string
+ fmt.Fprintf(c.Stdout, "%s [Y/n] ", question)
+ fmt.Fscanln(c.Stdin, &answer)
+ answer = strings.TrimSpace(strings.ToLower(answer))
+ switch answer {
+ case "y", "":
+ return true, nil
+ case "n":
+ return false, nil
+ default:
+ c.printErr(fmt.Errorf("please answer 'Y' or 'n'"))
+ }
+ }
+}
+
// target creates a target according the configuration of this CLI and given opts.
func (c *CLI) target(opts targetOptions) (vespa.Target, error) {
targetType, err := c.targetType()