Skip to content

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Apr 9, 2023

fix docker info --format=json not outputting json format

The --format=json option was added for all inspect commands, but was not implemented for "docker info". This patch implements the missing option.

Before this patch:

docker info --format=json
json

With this patch applied:

docker info --format=json
{"ID":"80c2f18a-2c88-4e4a-ba69-dca0eea59835","Containers":7,"ContainersRunning":"..."}

fix docker version --format=json not outputting json format

The --format=json option was added for all inspect commands, but was not
implemented for "docker version". This patch implements the missing option.

Before this patch:

docker version --format=json
json

With this patch:

docker version --format=json
{"Client":{"Platform":{"Name":""},"Version":"24.0.0-dev","ApiVersion":"..."}}

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter
Copy link

codecov-commenter commented Apr 9, 2023

Codecov Report

Merging #4168 (ed1c775) into master (daf99dd) will increase coverage by 0.01%.
The diff coverage is 80.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4168      +/-   ##
==========================================
+ Coverage   59.03%   59.04%   +0.01%     
==========================================
  Files         288      288              
  Lines       24776    24775       -1     
==========================================
+ Hits        14627    14629       +2     
+ Misses       9265     9262       -3     
  Partials      884      884              

@thaJeztah thaJeztah marked this pull request as ready for review April 9, 2023 12:31
@thaJeztah
Copy link
Member Author

@silvin-lubecki @vvoland @laurazard ptal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The --format=json option was added for all inspect commands, but was not implemented
for "docker info". This patch implements the missing option.

Before this patch:

    docker info --format=json
    json

With this patch applied:

    docker info --format=json
    {"ID":"80c2f18a-2c88-4e4a-ba69-dca0eea59835","Containers":7,"ContainersRunning":"..."}

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The --format=json option was added for all inspect commands, but was not
implemented for "docker version". This patch implements the missing option.

Before this patch:

    docker version --format=json
    json

With this patch:

    docker version --format=json
    {"Client":{"Platform":{"Name":""},"Version":"24.0.0-dev","ApiVersion":"..."}}

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah changed the title fix docker info --format=json not outputting json format fix docker info, docker version --format=json not outputting json format Apr 10, 2023
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sneaky little commit that's unrelated :)

Copy link
Member Author

@thaJeztah thaJeztah Apr 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a .golden file, and used for the extra test-case that was added;

assert.Check(t, golden.String(cli.OutBuffer().String(), "docker-client-version.json.golden"))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 so I thought you meant that JSON file, but it was referring to the "make it a const" commit. I had that in another PR, but doing it later would mean we had more code-churn, as the lines using it are touched by this PR, so I moved it first to prevent that.

@@ -507,6 +506,10 @@ func printServerWarningsLegacy(dockerCli command.Cli, info types.Info) {
}

func formatInfo(dockerCli command.Cli, info info, format string) error {
if format == formatter.JSONFormatKey {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unfortunate, changing the parameter on fly is not great

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the system info printing is quite involved currently. I can use a new variable for it if you prefer but thought to keep it simple (it's not passed by reference in either case, so only used here).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want the system info formatting to go to the formatting package?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, we'd have to look. I think there's been some back-and-forth in the past; a single "formatting" package would also have to import all the types used by all objects, so I think it originally was a single package, then got split to each object type. to allow for specific logic for each where needed.

Definitely something to look at what the current state is, and if things are all in the right place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants