From 67ae2c0976dce370742aa2788375979ac9acb8b3 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 31 Aug 2022 18:40:37 +0200 Subject: [PATCH] cli: createContainer() remove intermediate variable Having the intermediate variable made it difficult to see if it was possibly mutated and/or something special done with it, so just use the cli's accessors to get its Err(). Signed-off-by: Sebastiaan van Stijn --- cli/command/container/create.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 17d868e420..a3e8dd09ac 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -203,10 +203,9 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig config := containerConfig.Config hostConfig := containerConfig.HostConfig networkingConfig := containerConfig.NetworkingConfig - stderr := dockerCli.Err() - warnOnOomKillDisable(*hostConfig, stderr) - warnOnLocalhostDNS(*hostConfig, stderr) + warnOnOomKillDisable(*hostConfig, dockerCli.Err()) + warnOnLocalhostDNS(*hostConfig, dockerCli.Err()) var ( trustedRef reference.Canonical @@ -237,7 +236,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig } pullAndTagImage := func() error { - pullOut := stderr + pullOut := dockerCli.Err() if opts.quiet { pullOut = io.Discard } @@ -277,7 +276,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig if apiclient.IsErrNotFound(err) && namedRef != nil && opts.pull == PullImageMissing { if !opts.quiet { // we don't want to write to stdout anything apart from container.ID - fmt.Fprintf(stderr, "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef)) + fmt.Fprintf(dockerCli.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef)) } if err := pullAndTagImage(); err != nil { @@ -295,7 +294,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig } for _, warning := range response.Warnings { - fmt.Fprintf(stderr, "WARNING: %s\n", warning) + fmt.Fprintf(dockerCli.Err(), "WARNING: %s\n", warning) } err = containerIDFile.Write(response.ID) return &response, err