Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

images: print hint when invoking "docker images" with ambiguous argument #4849

Merged
merged 3 commits into from
Feb 5, 2024

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Feb 3, 2024

cli/command/images: runImages: inline intermediate var

cli/command/images: runImages: use proper camel-case for dockerCLI

images: print hint when invoking "docker images" with ambiguous argument

The docker images top-level subcommand predates the docker <object> <verb>
convention (e.g. docker image ls), but accepts a positional argument to
search/filter images by name (globbing). It's common for users to accidentally
mistake these commands, and to use (e.g.) docker images ls, expecting
to see all images, but ending up with an empty list because no image named
"ls" was found.

Disallowing these search-terms would be a breaking change, but we can print
and informational message to help the users correct their mistake.

Before this patch:

docker images ls
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

With this patch applied:

docker images ls
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

No images found matching "ls": did you mean "docker image ls"?

- Description for the changelog

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

print hint when invoking "docker images" with ambiguous argument

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The `docker images` top-level subcommand predates the `docker <object> <verb>`
convention (e.g. `docker image ls`), but accepts a positional argument to
search/filter images by name (globbing). It's common for users to accidentally
mistake these commands, and to use (e.g.) `docker images ls`, expecting
to see all images, but ending up with an empty list because no image named
"ls" was found.

Disallowing these search-terms would be a breaking change, but we can print
and informational message to help the users correct their mistake.

Before this patch:

    docker images ls
    REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

With this patch applied:

    docker images ls
    REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

    No images found matching "ls": did you mean "docker image ls"?

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@codecov-commenter
Copy link

Codecov Report

Merging #4849 (809eb8c) into master (2936816) will increase coverage by 1.69%.
Report is 691 commits behind head on master.
The diff coverage is 62.29%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4849      +/-   ##
==========================================
+ Coverage   59.58%   61.28%   +1.69%     
==========================================
  Files         288      287       -1     
  Lines       24821    20038    -4783     
==========================================
- Hits        14790    12280    -2510     
+ Misses       9145     6866    -2279     
- Partials      886      892       +6     

Copy link
Collaborator

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

Overall LGTM.
Glad to have something in place for this.

Format: formatter.NewImageFormat(format, options.quiet, options.showDigests),
Trunc: !options.noTrunc,
},
Digest: options.showDigests,
}
return formatter.ImageWrite(imageCtx, images)
if err := formatter.ImageWrite(imageCtx, images); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why print the empty image list before checking if its ambiguous?
I guess it can make it a little more obvious what could be happening.

Copy link
Member Author

Choose a reason for hiding this comment

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

I continued treating as a regular search that didn't return a result. eg, a search for an image named build could still be legit, so keeping the behavior as usual, just the extra message on stderr

@thaJeztah
Copy link
Member Author

@laurazard @jalonsogo ptal 🤗

Copy link
Collaborator

@laurazard laurazard left a comment

Choose a reason for hiding this comment

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

LGTM!

@thaJeztah
Copy link
Member Author

Thanks all! Let me bring this in; we can tweak the hint if we want to in follow ups.

@thaJeztah thaJeztah merged commit ce3b07c into docker:master Feb 5, 2024
77 checks passed
@thaJeztah thaJeztah deleted the image_list_dedup branch February 5, 2024 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants