Skip to content

Conversation

doringeman
Copy link

@doringeman doringeman commented Sep 11, 2025

- What I did

Enabled completion for docker images.

- How I did it

By adding a new ImageNamesWithBase completion function which offers completion for images present within the local store, including both full image names with tags and base image names (repository names only) when multiple tags exist for the same base name.

- How to verify it

$ ./build/docker images docker/docker-model-<TAB>
docker/docker-model-backend-llamacpp:v0.0.8-rc2-metal  docker/docker-model-cli-desktop-module
docker/docker-model-cli-desktop-module:v0.1.32         docker/docker-model-cli-desktop-module:v0.1.33

$ ./build/docker images docker/docker-model-cli-desktop-module
REPOSITORY                               TAG       IMAGE ID       CREATED        SIZE
docker/docker-model-cli-desktop-module   v0.1.33   e0774d732e37   2 months ago   25.4MB
docker/docker-model-cli-desktop-module   v0.1.32   a638160de27e   2 months ago   26.9MB

- Human readable description for the release notes

Add image name completion for `docker images`.

- A picture of a cute animal (not mandatory but encouraged)
image
Source: https://earth.org/world-lemur-day/.

@doringeman doringeman force-pushed the image-list-completions branch from 7672399 to 0fdbc75 Compare September 11, 2025 14:36
@codecov-commenter
Copy link

codecov-commenter commented Sep 11, 2025

Codecov Report

❌ Patch coverage is 0% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli/command/completion/functions.go 0.00% 22 Missing ⚠️

📢 Thoughts on this report? Let us know!

names = append(names, baseName)
}
}
return names, cobra.ShellCompDirectiveNoSpace
Copy link
Collaborator

Choose a reason for hiding this comment

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

This still needs the ShellCompDirectiveNoFileComp to avoid completing files when there's no images

Suggested change
return names, cobra.ShellCompDirectiveNoSpace
return names, cobra.ShellCompDirectiveNoSpace | ShellCompDirectiveNoFileComp

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, wondering if the NoSpace is even needed if we have both the base name (like alpine) and the individual tags (alpine:latest, alpine:3.20, ...).

Copy link
Author

Choose a reason for hiding this comment

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

I added NoSpace so I can select the base name and then continue seeing it with all the tags. There are no completing files if I'm using NoSpace.

Screenshot 2025-09-12 at 17 02 49 Screenshot 2025-09-12 at 17 03 27

Copy link
Collaborator

Choose a reason for hiding this comment

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

But if there are no images, then NoSpace alone would still show files. (at least that's what I'm seeing with fish)

Copy link
Author

Choose a reason for hiding this comment

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

Oh, OK, TIL! Updated. Thank you!

@doringeman doringeman force-pushed the image-list-completions branch from f3f88ae to 74d0210 Compare September 12, 2025 14:33
for _, img := range list {
names = append(names, img.RepoTags...)
for _, tag := range img.RepoTags {
if baseName, _, ok := strings.Cut(tag, ":"); ok {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could use the reference.Parse* function... Otherwise it will produce truncated image names for images on repos using non-standard port like localhost:5000/myimage:latest

@vvoland vvoland requested a review from thaJeztah September 12, 2025 16:27
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