Skip to content

Commit 0563fa6

Browse files
committed
cli/command/system/runInfo: set negotiated API version when available
The current logic was ignoring (e.g.) `--format=json` formats, and was only setting the negotiated API version if no format was specified. While we do want to avoid calling the API if possible, we do already check if the given template requires a server connection, so let's move updating the API version to that block. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent fc99fe2 commit 0563fa6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cli/command/system/info.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,14 @@ func runInfo(ctx context.Context, cmd *cobra.Command, dockerCli command.Cli, opt
101101
var serverConnErr error
102102
if needsServerInfo(opts.format, info) {
103103
serverConnErr = addServerInfo(ctx, dockerCli, opts.format, &info)
104+
if serverConnErr == nil {
105+
// Update client API version after it was negotiated.
106+
info.ClientInfo.APIVersion = dockerCli.CurrentVersion()
107+
}
104108
}
105109

106110
if opts.format == "" {
107111
info.UserName = dockerCli.ConfigFile().AuthConfigs[registry.IndexServer].Username
108-
info.ClientInfo.APIVersion = dockerCli.CurrentVersion()
109112
return errors.Join(prettyPrintInfo(dockerCli, info), serverConnErr)
110113
}
111114

0 commit comments

Comments
 (0)