Skip to content

Commit bd6d500

Browse files
committed
cli/command/container: inline uses of streams.Out.CheckTty
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent fbfb69f commit bd6d500

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

cli/command/container/attach.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,20 @@ func RunAttach(ctx context.Context, dockerCLI command.Cli, containerID string, o
8989
return err
9090
}
9191

92-
if err := dockerCLI.In().CheckTty(!opts.NoStdin, c.Config.Tty); err != nil {
93-
return err
92+
attachStdin := !opts.NoStdin
93+
if attachStdin {
94+
// TODO(thaJeztah): should this also check if c.Config.OpenStdin is true, and produce an error otherwise?
95+
if !c.Config.Tty {
96+
return errors.New("cannot attach stdin because the container is not a TTY-enabled container")
97+
}
98+
if !dockerCLI.In().IsTerminal() {
99+
return errors.New("cannot attach stdin because stdin is not a terminal")
100+
}
94101
}
95102

96103
options := client.ContainerAttachOptions{
97104
Stream: true,
98-
Stdin: !opts.NoStdin && c.Config.OpenStdin,
105+
Stdin: attachStdin && c.Config.OpenStdin,
99106
Stdout: true,
100107
Stderr: true,
101108
DetachKeys: detachKeys,

cli/command/container/exec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ func RunExec(ctx context.Context, dockerCLI command.Cli, containerIDorName strin
101101
return err
102102
}
103103
if !options.Detach {
104-
if err := dockerCLI.In().CheckTty(execOptions.AttachStdin, execOptions.TTY); err != nil {
105-
return err
104+
if execOptions.AttachStdin && execOptions.TTY && !dockerCLI.In().IsTerminal() {
105+
return errors.New("cannot attach stdin to a TTY-enabled container because stdin is not a terminal")
106106
}
107107
}
108108

cli/command/container/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ func runContainer(ctx context.Context, dockerCli command.Cli, runOpts *runOption
126126
config.ArgsEscaped = false
127127

128128
if !runOpts.detach {
129-
if err := dockerCli.In().CheckTty(config.AttachStdin, config.Tty); err != nil {
130-
return err
129+
if config.AttachStdin && config.Tty && !dockerCli.In().IsTerminal() {
130+
return errors.New("cannot attach stdin to a TTY-enabled container because stdin is not a terminal")
131131
}
132132
} else {
133133
if copts.attach.Len() != 0 {

0 commit comments

Comments
 (0)