summaryrefslogtreecommitdiff
path: root/questionUser.go
blob: c212334e0cf8d26c719637360ebd8ba598f0ad4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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:
			if strings.HasPrefix(line, "y") {
				return true
			}
			return false
		}
	}
	return false
}