mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Exit if there is any error reading from stdin.
This commit is contained in:
parent
2357fecc92
commit
6e4a818ee6
2 changed files with 8 additions and 7 deletions
13
commands.go
13
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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}()
|
||||
|
|
Loading…
Add table
Reference in a new issue