From fc6be6ad3027292963d9229777aa4305a4ef15ff Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 1 Apr 2022 12:24:44 +0200 Subject: [PATCH] cli: pass dockerCLI's in/out/err to cobra cmds Both the DockerCLI and Cobra Commands provide accessors for Input, Output, and Error streams (usually STDIN, STDOUT, STDERR). While we were already passing DockerCLI's Output to Cobra, we were not doing so for the other streams (and were passing none for plugin commands), potentially resulting in DockerCLI output/input to mean something else than a Cobra Command's intput/output/error. This patch sets them to the same streams when constructing the Cobra command. Signed-off-by: Sebastiaan van Stijn --- cli-plugins/plugin/plugin.go | 2 ++ cmd/docker/docker.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/cli-plugins/plugin/plugin.go b/cli-plugins/plugin/plugin.go index 3d98662220..bdb5a64875 100644 --- a/cli-plugins/plugin/plugin.go +++ b/cli-plugins/plugin/plugin.go @@ -133,7 +133,9 @@ func newPluginCommand(dockerCli *command.DockerCli, plugin *cobra.Command, meta } opts, flags := cli.SetupPluginRootCommand(cmd) + cmd.SetIn(dockerCli.In()) cmd.SetOut(dockerCli.Out()) + cmd.SetErr(dockerCli.Err()) cmd.AddCommand( plugin, diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index 78336bea24..9becec2c07 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -51,6 +51,10 @@ func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand { DisableDescriptions: true, }, } + cmd.SetIn(dockerCli.In()) + cmd.SetOut(dockerCli.Out()) + cmd.SetErr(dockerCli.Err()) + opts, flags, helpCmd = cli.SetupRootCommand(cmd) registerCompletionFuncForGlobalFlags(dockerCli, cmd) flags.BoolP("version", "v", false, "Print version information and quit")