From 5f13d0f2b5a57a27932a177e0d766ed65b492b79 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 8 Mar 2025 19:22:29 +0100 Subject: [PATCH 1/2] remove uses of cli.DefaultVersion() It's hard-coded to the API defaultversion, so we can use that const directly. Ultimately, this should be something returned by the API client configured on the CLI, not the CLI itself. Signed-off-by: Sebastiaan van Stijn --- cli/command/cli.go | 2 +- cli/command/system/version.go | 17 +++++++++-------- internal/test/cli.go | 5 +++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cli/command/cli.go b/cli/command/cli.go index 2f3d4ab240..8b5780d6b7 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -88,7 +88,7 @@ type DockerCli struct { enableGlobalMeter, enableGlobalTracer bool } -// DefaultVersion returns api.defaultVersion. +// DefaultVersion returns [api.DefaultVersion]. func (*DockerCli) DefaultVersion() string { return api.DefaultVersion } diff --git a/cli/command/system/version.go b/cli/command/system/version.go index 0e0422bd40..f84569767d 100644 --- a/cli/command/system/version.go +++ b/cli/command/system/version.go @@ -16,6 +16,7 @@ import ( flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/cli/version" "github.com/docker/cli/templates" + "github.com/docker/docker/api" "github.com/docker/docker/api/types" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -89,20 +90,20 @@ type clientVersion struct { // information. func newClientVersion(contextName string, dockerCli command.Cli) clientVersion { v := clientVersion{ - Version: version.Version, - GoVersion: runtime.Version(), - GitCommit: version.GitCommit, - BuildTime: reformatDate(version.BuildTime), - Os: runtime.GOOS, - Arch: arch(), - Context: contextName, + Version: version.Version, + DefaultAPIVersion: api.DefaultVersion, + GoVersion: runtime.Version(), + GitCommit: version.GitCommit, + BuildTime: reformatDate(version.BuildTime), + Os: runtime.GOOS, + Arch: arch(), + Context: contextName, } if version.PlatformName != "" { v.Platform = &platformInfo{Name: version.PlatformName} } if dockerCli != nil { v.APIVersion = dockerCli.CurrentVersion() - v.DefaultAPIVersion = dockerCli.DefaultVersion() } return v } diff --git a/internal/test/cli.go b/internal/test/cli.go index 35e4a317a5..8b506e1414 100644 --- a/internal/test/cli.go +++ b/internal/test/cli.go @@ -14,6 +14,7 @@ import ( registryclient "github.com/docker/cli/cli/registry/client" "github.com/docker/cli/cli/streams" "github.com/docker/cli/cli/trust" + "github.com/docker/docker/api" "github.com/docker/docker/client" notaryclient "github.com/theupdateframework/notary/client" ) @@ -104,8 +105,8 @@ func (c *FakeCli) Client() client.APIClient { } // CurrentVersion returns the API version used by FakeCli. -func (c *FakeCli) CurrentVersion() string { - return c.DefaultVersion() +func (*FakeCli) CurrentVersion() string { + return api.DefaultVersion } // Out returns the output stream (stdout) the cli should write on From 79c9c7e3e4a72954c13e14942d4dbcdd21be0ac3 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 8 Mar 2025 19:29:12 +0100 Subject: [PATCH 2/2] cli/command/system: ignore unhandled errors Signed-off-by: Sebastiaan van Stijn --- cli/command/system/version.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/command/system/version.go b/cli/command/system/version.go index f84569767d..3a0ad75c35 100644 --- a/cli/command/system/version.go +++ b/cli/command/system/version.go @@ -197,8 +197,8 @@ func runVersion(ctx context.Context, dockerCli command.Cli, opts *versionOptions func prettyPrintVersion(dockerCli command.Cli, vd versionInfo, tmpl *template.Template) error { t := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 1, ' ', 0) err := tmpl.Execute(t, vd) - t.Write([]byte("\n")) - t.Flush() + _, _ = t.Write([]byte("\n")) + _ = t.Flush() return err }