mirror of https://github.com/docker/cli.git
Slight cleanup/refactor of attachContainer
Return early in case there's an error, and declare variables closer to where they're used. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
c7adb47076
commit
16131fb459
|
@ -214,32 +214,7 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func attachContainer(
|
func attachContainer(ctx context.Context, dockerCli command.Cli, errCh *chan error, config *container.Config, containerID string) (func(), error) {
|
||||||
ctx context.Context,
|
|
||||||
dockerCli command.Cli,
|
|
||||||
errCh *chan error,
|
|
||||||
config *container.Config,
|
|
||||||
containerID string,
|
|
||||||
) (func(), error) {
|
|
||||||
stdout, stderr := dockerCli.Out(), dockerCli.Err()
|
|
||||||
var (
|
|
||||||
out, cerr io.Writer
|
|
||||||
in io.ReadCloser
|
|
||||||
)
|
|
||||||
if config.AttachStdin {
|
|
||||||
in = dockerCli.In()
|
|
||||||
}
|
|
||||||
if config.AttachStdout {
|
|
||||||
out = stdout
|
|
||||||
}
|
|
||||||
if config.AttachStderr {
|
|
||||||
if config.Tty {
|
|
||||||
cerr = stdout
|
|
||||||
} else {
|
|
||||||
cerr = stderr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
options := types.ContainerAttachOptions{
|
options := types.ContainerAttachOptions{
|
||||||
Stream: true,
|
Stream: true,
|
||||||
Stdin: config.AttachStdin,
|
Stdin: config.AttachStdin,
|
||||||
|
@ -253,6 +228,24 @@ func attachContainer(
|
||||||
return nil, errAttach
|
return nil, errAttach
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
out, cerr io.Writer
|
||||||
|
in io.ReadCloser
|
||||||
|
)
|
||||||
|
if config.AttachStdin {
|
||||||
|
in = dockerCli.In()
|
||||||
|
}
|
||||||
|
if config.AttachStdout {
|
||||||
|
out = dockerCli.Out()
|
||||||
|
}
|
||||||
|
if config.AttachStderr {
|
||||||
|
if config.Tty {
|
||||||
|
cerr = dockerCli.Out()
|
||||||
|
} else {
|
||||||
|
cerr = dockerCli.Err()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ch := make(chan error, 1)
|
ch := make(chan error, 1)
|
||||||
*errCh = ch
|
*errCh = ch
|
||||||
|
|
||||||
|
@ -284,7 +277,7 @@ func reportError(stderr io.Writer, name string, str string, withHelp bool) {
|
||||||
if withHelp {
|
if withHelp {
|
||||||
str += "\nSee 'docker " + name + " --help'."
|
str += "\nSee 'docker " + name + " --help'."
|
||||||
}
|
}
|
||||||
fmt.Fprintln(stderr, "docker:", str)
|
_, _ = fmt.Fprintln(stderr, "docker:", str)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if container start fails with 'not found'/'no such' error, return 127
|
// if container start fails with 'not found'/'no such' error, return 127
|
||||||
|
|
Loading…
Reference in New Issue