diff options
Diffstat (limited to 'questionUser.go')
| -rw-r--r-- | questionUser.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/questionUser.go b/questionUser.go new file mode 100644 index 0000000..3bba4ae --- /dev/null +++ b/questionUser.go @@ -0,0 +1,30 @@ +package fhelp + +import ( + "bufio" + "fmt" + "os" + "strings" + + "go.wit.com/log" +) + +func QuestionUser(msg string) bool { + log.Info(msg) + fmt.Fprintf(os.Stdout, "(y)es or (n)o ? ") + + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + line := scanner.Text() + line = strings.TrimSpace(line) + line = strings.ToLower(line) + switch line { + case "y": + return true + case "n": + return false + default: + } + } + return false +} |
