handle read errors in promptWithDefault
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user