mirror of https://github.com/docker/cli.git
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 <github@gone.nl>
This commit is contained in:
parent
6205b4eae6
commit
e484243c29
|
@ -29,7 +29,6 @@ import (
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/go-connections/tlsconfig"
|
"github.com/docker/go-connections/tlsconfig"
|
||||||
"github.com/moby/term"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
notaryclient "github.com/theupdateframework/notary/client"
|
notaryclient "github.com/theupdateframework/notary/client"
|
||||||
|
@ -407,6 +406,7 @@ func NewDockerCli(ops ...DockerCliOption) (*DockerCli, error) {
|
||||||
defaultOps := []DockerCliOption{
|
defaultOps := []DockerCliOption{
|
||||||
WithContentTrustFromEnv(),
|
WithContentTrustFromEnv(),
|
||||||
WithDefaultContextStoreConfig(),
|
WithDefaultContextStoreConfig(),
|
||||||
|
WithStandardStreams(),
|
||||||
}
|
}
|
||||||
ops = append(defaultOps, ops...)
|
ops = append(defaultOps, ops...)
|
||||||
|
|
||||||
|
@ -414,18 +414,6 @@ func NewDockerCli(ops ...DockerCliOption) (*DockerCli, error) {
|
||||||
if err := cli.Apply(ops...); err != nil {
|
if err := cli.Apply(ops...); err != nil {
|
||||||
return nil, err
|
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
|
return cli, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue