Skip to content

Commit 06b8da1

Browse files
committed
WIP: attach: pass container as argument
Trying to make "runAttach" not depend on attachOptions, and to see if we can make it accept container.AttachOptions instead relates to docker#4637 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent abf8cff commit 06b8da1

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

cli/command/container/attach.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,35 @@ func NewAttachCommand(dockerCLI command.Cli) *cobra.Command {
7373
func RunAttach(ctx context.Context, dockerCLI command.Cli, containerID string, opts *AttachOptions) error {
7474
apiClient := dockerCLI.Client()
7575

76-
// request channel to wait for client
77-
resultC, errC := apiClient.ContainerWait(ctx, containerID, "")
76+
attachStdIn := true
77+
if opts.NoStdin {
78+
// TODO(thaJeztah): this is the tricky one: can we use container.AttachOptions for this one without it being ambiguous?
79+
attachStdIn = false
80+
}
7881

7982
c, err := inspectContainerAndCheckState(ctx, apiClient, containerID)
8083
if err != nil {
8184
return err
8285
}
8386

84-
if err := dockerCLI.In().CheckTty(!opts.NoStdin, c.Config.Tty); err != nil {
85-
return err
87+
if attachStdIn {
88+
if err := dockerCLI.In().CheckTty(attachStdIn, c.Config.Tty); err != nil {
89+
return err
90+
}
91+
if !c.Config.OpenStdin {
92+
// TODO(thaJeztah): should this produce an error?
93+
attachStdIn = false
94+
}
8695
}
8796

88-
detachKeys := dockerCLI.ConfigFile().DetachKeys
89-
if opts.DetachKeys != "" {
90-
detachKeys = opts.DetachKeys
97+
detachKeys := opts.DetachKeys
98+
if opts.DetachKeys == "" {
99+
detachKeys = dockerCLI.ConfigFile().DetachKeys
91100
}
92101

93102
options := container.AttachOptions{
94103
Stream: true,
95-
Stdin: !opts.NoStdin && c.Config.OpenStdin,
104+
Stdin: attachStdIn,
96105
Stdout: true,
97106
Stderr: true,
98107
DetachKeys: detachKeys,
@@ -146,6 +155,8 @@ func RunAttach(ctx context.Context, dockerCLI command.Cli, containerID string, o
146155
return err
147156
}
148157

158+
// request channel to wait for client
159+
resultC, errC := apiClient.ContainerWait(ctx, containerID, "")
149160
return getExitStatus(errC, resultC)
150161
}
151162

0 commit comments

Comments
 (0)