mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-14 06:57:31 +00:00
util/prompt: make yes/no prompt reusable
Updates #19445 Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:

committed by
Kristoffer Dalby

parent
b3e74367d8
commit
9309760263
24
util/prompt/prompt.go
Normal file
24
util/prompt/prompt.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
// Package prompt provides a simple way to prompt the user for input.
|
||||
package prompt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// YesNo takes a question and prompts the user to answer the
|
||||
// question with a yes or no. It appends a [y/n] to the message.
|
||||
func YesNo(msg string) bool {
|
||||
fmt.Print(msg + " [y/n] ")
|
||||
var resp string
|
||||
fmt.Scanln(&resp)
|
||||
resp = strings.ToLower(resp)
|
||||
switch resp {
|
||||
case "y", "yes", "sure":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user