cmd/puppeth: remove wrapping loop in single reads

This commit is contained in:
Péter Szilágyi 2017-08-04 17:00:22 +02:00
parent 0cc9b8791e
commit 455fcc8309
No known key found for this signature in database
GPG Key ID: E9AE538CEDF8293D

View File

@ -106,17 +106,15 @@ func (w *wizard) readString() string {
// readDefaultString reads a single line from stdin, trimming if from spaces. If // readDefaultString reads a single line from stdin, trimming if from spaces. If
// an empty line is entered, the default value is returned. // an empty line is entered, the default value is returned.
func (w *wizard) readDefaultString(def string) string { func (w *wizard) readDefaultString(def string) string {
for { fmt.Printf("> ")
fmt.Printf("> ") text, err := w.in.ReadString('\n')
text, err := w.in.ReadString('\n') if err != nil {
if err != nil { log.Crit("Failed to read user input", "err", err)
log.Crit("Failed to read user input", "err", err)
}
if text = strings.TrimSpace(text); text != "" {
return text
}
return def
} }
if text = strings.TrimSpace(text); text != "" {
return text
}
return def
} }
// readInt reads a single line from stdin, trimming if from spaces, enforcing it // readInt reads a single line from stdin, trimming if from spaces, enforcing it
@ -207,15 +205,13 @@ func (w *wizard) readDefaultFloat(def float64) float64 {
// readPassword reads a single line from stdin, trimming it from the trailing new // readPassword reads a single line from stdin, trimming it from the trailing new
// line and returns it. The input will not be echoed. // line and returns it. The input will not be echoed.
func (w *wizard) readPassword() string { func (w *wizard) readPassword() string {
for { fmt.Printf("> ")
fmt.Printf("> ") text, err := terminal.ReadPassword(int(syscall.Stdin))
text, err := terminal.ReadPassword(int(syscall.Stdin)) if err != nil {
if err != nil { log.Crit("Failed to read password", "err", err)
log.Crit("Failed to read password", "err", err)
}
fmt.Println()
return string(text)
} }
fmt.Println()
return string(text)
} }
// readAddress reads a single line from stdin, trimming if from spaces and converts // readAddress reads a single line from stdin, trimming if from spaces and converts