Skip to content

Commit

Permalink
make runAttach public and allow passing context
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Nov 6, 2023
1 parent 9cb175f commit e3f237c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions cli/command/container/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewAttachCommand(dockerCli command.Cli) *cobra.Command {
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.container = args[0]
return runAttach(dockerCli, &opts)
return RunAttach(dockerCli, &opts)
},
Annotations: map[string]string{
"aliases": "docker container attach, docker attach",
Expand All @@ -70,8 +70,11 @@ func NewAttachCommand(dockerCli command.Cli) *cobra.Command {
return cmd
}

func runAttach(dockerCli command.Cli, opts *attachOptions) error {
ctx := context.Background()
func RunAttach(dockerCli command.Cli, opts *attachOptions) error {
return RunAttachWithContext(context.Background(), dockerCli, opts)
}

func RunAttachWithContext(ctx context.Context, dockerCli command.Cli, opts *attachOptions) error {
apiClient := dockerCli.Client()

// request channel to wait for client
Expand Down
6 changes: 5 additions & 1 deletion cli/command/container/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,16 @@ func NewExecCommand(dockerCli command.Cli) *cobra.Command {

// RunExec executes an `exec` command
func RunExec(dockerCli command.Cli, options ExecOptions) error {
return RunExecWithContext(context.Background(), dockerCli, options)
}

// RunExecWithContext executes an `exec` command
func RunExecWithContext(ctx context.Context, dockerCli command.Cli, options ExecOptions) error {
execConfig, err := parseExec(options, dockerCli.ConfigFile())
if err != nil {
return err
}

ctx := context.Background()
client := dockerCli.Client()

// We need to check the tty _before_ we do the ContainerExecCreate, because
Expand Down

0 comments on commit e3f237c

Please sign in to comment.