From e3f237cf3ac58e39260bf491dc888ec8f038e785 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Mon, 6 Nov 2023 10:00:13 +0100 Subject: [PATCH] make runAttach public and allow passing context Signed-off-by: Nicolas De Loof --- cli/command/container/attach.go | 9 ++++++--- cli/command/container/exec.go | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cli/command/container/attach.go b/cli/command/container/attach.go index b834197552f2..9a47b42b2a82 100644 --- a/cli/command/container/attach.go +++ b/cli/command/container/attach.go @@ -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", @@ -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 diff --git a/cli/command/container/exec.go b/cli/command/container/exec.go index 3160aaba83c6..b3153ca2edd4 100644 --- a/cli/command/container/exec.go +++ b/cli/command/container/exec.go @@ -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