summaryrefslogtreecommitdiff
path: root/questionUser.go
blob: 21399967e17111dc67e410eba0340ea3526eb129 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package fhelp

import (
	"bufio"
	"fmt"
	"os"
	"strings"

	"go.wit.com/log"
)

func QuestionUser(msg string) bool {
	// log.Info("START", 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":
			// log.Info("QUESTION USER Y", msg)
			return true
		case "n":
			// log.Info("QUESTION USER N", msg)
			return false
		default:
			// log.Info("QUESTION USER DEFAULT", msg)
			if strings.HasPrefix(line, "y") {
				return true
			}
			return false
		}
	}
	// log.Info("QUESTION USER END", msg)
	return false
}

func InputFromUser(msg string) string {
	log.Info(msg)
	fmt.Fprintf(os.Stdout, "")

	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		line := scanner.Text()
		line = strings.TrimSpace(line)
		line = strings.ToLower(line)
		switch line {
		case "":
			continue
		default:
			return line
		}
	}
	return ""
}