From 6e4a818ee65008a043d3ba8e5053cc43babb2f66 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Sat, 3 Aug 2013 17:27:15 -0700 Subject: [PATCH] Exit if there is any error reading from stdin. --- commands.go | 13 +++++++------ term/term.go | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/commands.go b/commands.go index 0643bc8d58..ecd9c63155 100644 --- a/commands.go +++ b/commands.go @@ -271,13 +271,14 @@ func (cli *DockerCli) CmdLogin(args ...string) error { } } - readInput := func(in io.Reader) (string, error) { + readInput := func(in io.Reader, out io.Writer) string { reader := bufio.NewReader(in) line, err := reader.ReadString('\n') if err != nil { - return "", err + fmt.Fprintln(out, err.Error()) + os.Exit(1) } - return line, nil + return line } authconfig, ok := cli.configFile.Configs[auth.IndexServerAddress()] @@ -287,7 +288,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error { if username == "" { promptDefault("Username", authconfig.Username) - username, _ = readInput(cli.in) + username = readInput(cli.in, cli.out) if username == "" { username = authconfig.Username } @@ -299,7 +300,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error { fmt.Fprintf(cli.out, "Password: ") term.DisableEcho(cli.terminalFd, cli.out, oldState) - password, _ = readInput(cli.in) + password = readInput(cli.in, cli.out) term.RestoreTerminal(cli.terminalFd, oldState) @@ -310,7 +311,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error { if email == "" { promptDefault("\nEmail", authconfig.Email) - email, _ = readInput(cli.in) + email = readInput(cli.in, cli.out) if email == "" { email = authconfig.Email } diff --git a/term/term.go b/term/term.go index 074319c287..2c78d6806e 100644 --- a/term/term.go +++ b/term/term.go @@ -71,7 +71,7 @@ func HandleInterrupt(fd uintptr, out io.Writer, state *State) { go func() { _ = <-sigchan - fmt.Fprintf(out, "\n") + fmt.Fprint(out, "\n") RestoreTerminal(fd, state) os.Exit(0) }()