handle read errors in promptWithDefault

This commit is contained in:
2026-03-04 21:22:01 +00:00
parent 5a58be10c8
commit fd9aeece00
2 changed files with 17 additions and 6 deletions
+7 -4
View File
@@ -43,7 +43,7 @@ func newReader() *bufio.Reader {
return stdinReader
}
func promptWithDefault(label, def string) string {
func promptWithDefault(label, def string) (string, error) {
reader := newReader()
if def != "" {
fmt.Printf("%s [%s]: ", label, def)
@@ -51,12 +51,15 @@ func promptWithDefault(label, def string) string {
fmt.Printf("%s: ", label)
}
text, _ := reader.ReadString('\n')
text, err := reader.ReadString('\n')
if err != nil {
return "", err
}
text = strings.TrimSpace(text)
if text == "" {
return def
return def, nil
}
return text
return text, nil
}
func promptYesNo(message string, def bool) (bool, error) {