From 5f1f19d9ca4bec7b285256845d04ac76222cda13 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 13 Dec 2024 12:34:31 -0600 Subject: use go-mod-clean --- stdin.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 stdin.go (limited to 'stdin.go') diff --git a/stdin.go b/stdin.go new file mode 100644 index 0000000..370bc27 --- /dev/null +++ b/stdin.go @@ -0,0 +1,57 @@ +package main + +import ( + "bufio" + "errors" + "fmt" + "os" + "strings" + + "go.wit.com/log" +) + +func showOptions(b bool, s []string) { + fmt.Println("") + for _, line := range s { + fmt.Println(line) + } + fmt.Println("") + if b { + fmt.Println("Enter (Y/n)") + } else { + fmt.Println("Enter (y/N)") + } +} + +// if b == true, default is to continue with 'Y' +func simpleStdin(b bool, s []string) { + /* + if argv.Auto { + return + } + */ + err := errors.New("user cancelled via stdin") + showOptions(b, s) + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + s := scanner.Text() + s = strings.TrimSpace(s) + s = strings.ToLower(s) + switch s { + case "y": + log.Info("got y") + return + case "n": + log.Info("got n") + badExit(err) + case "": + if b { + return + } else { + badExit(err) + } + default: + badExit(err) + } + } +} -- cgit v1.2.3