Skip to content

Commit

Permalink
WIP: attach: pass container as argument
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
thaJeztah committed Jan 26, 2024
1 parent abf8cff commit 06b8da1
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions cli/command/container/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,35 @@ func NewAttachCommand(dockerCLI command.Cli) *cobra.Command {
func RunAttach(ctx context.Context, dockerCLI command.Cli, containerID string, opts *AttachOptions) error {
apiClient := dockerCLI.Client()

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

c, err := inspectContainerAndCheckState(ctx, apiClient, containerID)
if err != nil {
return err
}

if err := dockerCLI.In().CheckTty(!opts.NoStdin, c.Config.Tty); err != nil {
return err
if attachStdIn {
if err := dockerCLI.In().CheckTty(attachStdIn, c.Config.Tty); err != nil {
return err
}
if !c.Config.OpenStdin {
// TODO(thaJeztah): should this produce an error?
attachStdIn = false
}
}

detachKeys := dockerCLI.ConfigFile().DetachKeys
if opts.DetachKeys != "" {
detachKeys = opts.DetachKeys
detachKeys := opts.DetachKeys
if opts.DetachKeys == "" {
detachKeys = dockerCLI.ConfigFile().DetachKeys
}

options := container.AttachOptions{
Stream: true,
Stdin: !opts.NoStdin && c.Config.OpenStdin,
Stdin: attachStdIn,
Stdout: true,
Stderr: true,
DetachKeys: detachKeys,
Expand Down Expand Up @@ -146,6 +155,8 @@ func RunAttach(ctx context.Context, dockerCLI command.Cli, containerID string, o
return err
}

// request channel to wait for client
resultC, errC := apiClient.ContainerWait(ctx, containerID, "")
return getExitStatus(errC, resultC)
}

Expand Down

0 comments on commit 06b8da1

Please sign in to comment.