summaryrefslogtreecommitdiff
path: root/stdin.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-11 00:03:08 -0600
committerJeff Carr <[email protected]>2024-12-11 00:03:08 -0600
commitb5a5732ead91ca963ca56341e8993c2c502345f5 (patch)
treec6fc59549d4cc30ec9267be436e9b877f940e5a5 /stdin.go
parentb952bb8adbb6d161382fc95cf70d7e26e74c5f05 (diff)
purge() go cache files
Diffstat (limited to 'stdin.go')
-rw-r--r--stdin.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/stdin.go b/stdin.go
new file mode 100644
index 0000000..9093246
--- /dev/null
+++ b/stdin.go
@@ -0,0 +1,55 @@
+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.Lower(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)
+ }
+ }
+}