cli/command/system: define struct for formatting version

The client.ServerVersion method in the moby/client module defines
an output struct that's separate from the API response. These output
structs are not designed to be marshaled as JSON, but the CLI depended
on them defining `json` labels, which it used to format the output
as JSON (`docker version --format=json`); as a result, the JSON output
changed in docker v29, as it would now use the naming based on the Go
struct's fields (`APIVersion` instead of `ApiVersion`).

In future, we should consider having a `--raw` (or similar) option for
the CLI to print API responses as-is, instead of using client structs
or CLI structs for this (this would also make sure the JSON output does
not inherit client-side formatting of fields).

For now, let's create a struct for formatting the output, similar to what
we do for the client-side information.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-11-12 13:57:50 +01:00
parent 3d4129b9ea
commit bff56f0493
4 changed files with 85 additions and 36 deletions

View File

@ -47,8 +47,18 @@ func TestVersionFormat(t *testing.T) {
BuildTime: "Wed May 30 22:21:05 2018",
Context: "my-context",
},
Server: &client.ServerVersionResult{
Platform: client.PlatformInfo{Name: "Docker Enterprise Edition (EE) 2.0"},
Server: &serverVersion{
Platform: client.PlatformInfo{Name: "Docker Enterprise Edition (EE) 2.0"},
Version: "18.99.5-ce",
APIVersion: "1.30",
MinAPIVersion: "1.12",
Os: "linux",
Arch: "amd64",
GitCommit: "64ddfa6",
GoVersion: "go1.8.7",
KernelVersion: "v1.0.0",
Experimental: false,
BuildTime: "Mon Jul 9 23:38:38 2018",
Components: []system.ComponentVersion{
{
Name: "Engine",