Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

docker run, create: add shell completion for CDI devices for "--device" #6450

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

Draft
thaJeztah wants to merge 2 commits into docker:master
base: master
Choose a base branch
Loading
from thaJeztah:complete_cdi_devices

Conversation

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Sep 10, 2025

docker run, create: add shell completion for CDI devices for "--device"

With this patch:

docker info --format '{{json .DiscoveredDevices}}'
[{"Source":"cdi","ID":"docker.com/gpu=webgpu"}]
docker container create --device=<tab>
docker container create --device=docker.com/gpu=webgpu
docker run --device=docker.com/gpu=webgpu
docker run --device=<tab>

- How to verify it

- Human readable description for the release notes

Add shell completion for CDI devices for "--device" on `docker run` and `docker create`

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

With this patch:
 docker info --format '{{json .DiscoveredDevices}}'
 [{"Source":"cdi","ID":"docker.com/gpu=webgpu"}]
 docker container create --device=<tab>
 docker container create --device=docker.com/gpu=webgpu
 docker run --device=docker.com/gpu=webgpu
 docker run --device=<tab>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Copy link

Codecov Report

❌ Patch coverage is 10.52632% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli/command/container/completion.go 10.52% 16 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Comment on lines 159 to 165
func completeCDIDevices(dockerCLI completion.APIClientProvider) cobra.CompletionFunc {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if strings.HasPrefix(toComplete, "/") {
return nil, cobra.ShellCompDirectiveDefault | cobra.ShellCompDirectiveNoSpace
}

info, err := dockerCLI.Client().Info(cmd.Context())
Copy link
Member Author

@thaJeztah thaJeztah Sep 10, 2025

Choose a reason for hiding this comment

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

Opening as draft, because I had this branch but after implementing CDI completion, I realised we also need to provide completion for file-paths (assuming the daemon and CLI are on the same host), so we need some solid way to distinguish "user wants to complete a CDI device" vs "user wants to add a device (e.g. /dev/foo:/some/path).

Comment on lines 170 to 174
devices = append(devices, di.ID)
devices = append(devices, cobra.CompletionWithDesc(di.ID, "CDI device"))
Copy link
Member Author

@thaJeztah thaJeztah Sep 10, 2025

Choose a reason for hiding this comment

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

Still on the fence if cobra.CompletionWithDesc is a bit "too much"; it's the equivalent of <value> + \t + <description>. I guess it's slightly more expressive, but also makes it look more magical than it is 😂

@thaJeztah thaJeztah modified the milestones: 29.0.0, 29.2.0 Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

29.2.0

Development

Successfully merging this pull request may close these issues.

CDI: --device shell completion

AltStyle によって変換されたページ (->オリジナル) /