mirror of https://github.com/docker/docs.git
Exit if there is any error reading from stdin.
This commit is contained in:
parent
75ac50a9a0
commit
4089a20cf4
13
commands.go
13
commands.go
|
@ -272,13 +272,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)
|
reader := bufio.NewReader(in)
|
||||||
line, err := reader.ReadString('\n')
|
line, err := reader.ReadString('\n')
|
||||||
if err != nil {
|
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()]
|
authconfig, ok := cli.configFile.Configs[auth.IndexServerAddress()]
|
||||||
|
@ -288,7 +289,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
||||||
|
|
||||||
if username == "" {
|
if username == "" {
|
||||||
promptDefault("Username", authconfig.Username)
|
promptDefault("Username", authconfig.Username)
|
||||||
username, _ = readInput(cli.in)
|
username = readInput(cli.in, cli.out)
|
||||||
if username == "" {
|
if username == "" {
|
||||||
username = authconfig.Username
|
username = authconfig.Username
|
||||||
}
|
}
|
||||||
|
@ -300,7 +301,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
||||||
fmt.Fprintf(cli.out, "Password: ")
|
fmt.Fprintf(cli.out, "Password: ")
|
||||||
|
|
||||||
term.DisableEcho(cli.terminalFd, cli.out, oldState)
|
term.DisableEcho(cli.terminalFd, cli.out, oldState)
|
||||||
password, _ = readInput(cli.in)
|
password = readInput(cli.in, cli.out)
|
||||||
|
|
||||||
term.RestoreTerminal(cli.terminalFd, oldState)
|
term.RestoreTerminal(cli.terminalFd, oldState)
|
||||||
|
|
||||||
|
@ -311,7 +312,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
||||||
|
|
||||||
if email == "" {
|
if email == "" {
|
||||||
promptDefault("\nEmail", authconfig.Email)
|
promptDefault("\nEmail", authconfig.Email)
|
||||||
email, _ = readInput(cli.in)
|
email = readInput(cli.in, cli.out)
|
||||||
if email == "" {
|
if email == "" {
|
||||||
email = authconfig.Email
|
email = authconfig.Email
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ func HandleInterrupt(fd uintptr, out io.Writer, state *State) {
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
_ = <-sigchan
|
_ = <-sigchan
|
||||||
fmt.Fprintf(out, "\n")
|
fmt.Fprint(out, "\n")
|
||||||
RestoreTerminal(fd, state)
|
RestoreTerminal(fd, state)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in New Issue