From e484243c29a45a34ff4e01900370f9399a02eadc Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 31 Aug 2022 17:10:53 +0200 Subject: [PATCH] cli/command: NewDockerCli(): use WithStandardStreams() `NewDockerCli` was configuring the standard streams using local code; this patch instead uses the available `WithStandardStreams()` option to do the same. There is slight difference in the order of events; Previously, user-provided options would be applied first, after which NewDockerCli would check if any of "in", "out", or "err" were nil, and if so set them to the default stream (or writer) for that output. The new code unconditionally sets the defaults _before_ applying user-provided options. In practive, howver, this makes no difference; the fields set are not exported, and the only functions updating them are `WithStandardStreams`, `WithInputStream`, and `WithCombinedStream`, neither of which checks the old value (so always overrides). Signed-off-by: Sebastiaan van Stijn --- cli/command/cli.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/cli/command/cli.go b/cli/command/cli.go index ba86491aef..c2b5bcc7ab 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -29,7 +29,6 @@ import ( "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "github.com/docker/go-connections/tlsconfig" - "github.com/moby/term" "github.com/pkg/errors" "github.com/spf13/cobra" notaryclient "github.com/theupdateframework/notary/client" @@ -407,6 +406,7 @@ func NewDockerCli(ops ...DockerCliOption) (*DockerCli, error) { defaultOps := []DockerCliOption{ WithContentTrustFromEnv(), WithDefaultContextStoreConfig(), + WithStandardStreams(), } ops = append(defaultOps, ops...) @@ -414,18 +414,6 @@ func NewDockerCli(ops ...DockerCliOption) (*DockerCli, error) { if err := cli.Apply(ops...); err != nil { return nil, err } - if cli.out == nil || cli.in == nil || cli.err == nil { - stdin, stdout, stderr := term.StdStreams() - if cli.in == nil { - cli.in = streams.NewIn(stdin) - } - if cli.out == nil { - cli.out = streams.NewOut(stdout) - } - if cli.err == nil { - cli.err = stderr - } - } return cli, nil }