diff options
| author | ishaan <contact@ishaan.cc> | 2026-07-12 16:41:00 +0530 |
|---|---|---|
| committer | ishaan <contact@ishaan.cc> | 2026-07-12 16:41:00 +0530 |
| commit | 050db499d18c61d90a68096027ac0d5aaa842f57 (patch) | |
| tree | 2d0cd6db07407c2d44c8ea7ec899fb3088766d01 /internal/utils/cli.go | |
| parent | 7b5328536a82755c2724f2075c31035d709588df (diff) | |
add init/new/edit subcommands, config, mlock/cleared sensitive info
Diffstat (limited to 'internal/utils/cli.go')
| -rw-r--r-- | internal/utils/cli.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/utils/cli.go b/internal/utils/cli.go new file mode 100644 index 0000000..773b529 --- /dev/null +++ b/internal/utils/cli.go @@ -0,0 +1,34 @@ +package utils + +import ( + "bufio" + "fmt" + "os" + "strings" +) + +func AskUserYesNo(prompt string, defaultVal bool) (bool, error) { + suffix := "[y/N]" + if defaultVal { + suffix = "[Y/n]" + } + + scanner := bufio.NewScanner(os.Stdin) + fmt.Printf("%s %s ", prompt, suffix) + scanner.Scan() + if err := scanner.Err(); err != nil { + return false, fmt.Errorf("failed to read confirmation: %w", err) + } + + input := strings.TrimSpace(scanner.Text()) + if input == "" { + return defaultVal, nil + } + + switch strings.ToUpper(input) { + case "Y", "YE", "YES": + return true, nil + default: + return false, nil + } +} |