-
Notifications
You must be signed in to change notification settings - Fork 2k
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
base: master
Are you sure you want to change the base?
Conversation
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 <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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()) |
There was a problem hiding this comment.
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
).
devices = append(devices, di.ID) | ||
devices = append(devices, cobra.CompletionWithDesc(di.ID, "CDI device")) |
There was a problem hiding this comment.
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 😂
--device
shell completion #6152docker run, create: add shell completion for CDI devices for "--device"
With this patch:
- How to verify it
- Human readable description for the release notes
- A picture of a cute animal (not mandatory but encouraged)