From 7c4413ab4ad8383bdbd8cb3bf616c30026cfb0fe Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Tue, 6 Dec 2016 17:28:58 -0800 Subject: [PATCH] Permit usernames with spaces. (#178) + We have an account with a space in it; the tool should accomodate this. + Additionally, support supplying only the username to the program. --- cmd/ro/main.go | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/cmd/ro/main.go b/cmd/ro/main.go index f9ccd55..c7759a9 100644 --- a/cmd/ro/main.go +++ b/cmd/ro/main.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "encoding/base64" "encoding/json" "flag" @@ -76,13 +77,33 @@ func registerFlags() { flag.DurationVar(&pollInterval, "poll-interval", time.Second, "interval for polling an outstanding order (set 0 to disable polling)") } +func readLine(prompt string) (line string, err error) { + fmt.Printf(prompt) + rd := bufio.NewReader(os.Stdin) + line, err = rd.ReadString('\n') + if err != nil { + return + } + line = strings.TrimSpace(line) + return +} + func getUserCredentials() { - user = os.Getenv(userEnv) - pswd = os.Getenv(pswdEnv) - if user == "" || pswd == "" { - fmt.Print("Username:") - fmt.Scan(&user) - var err error + var err error + if user == "" { + user = os.Getenv(userEnv) + } + + if pswd == "" { + pswd = os.Getenv(pswdEnv) + } + + if user == "" { + user, err = readLine("Username: ") + processError(err) + } + + if pswd == "" { pswd, err = gopass.GetPass("Password:") processError(err) }