Skip to content

Commit 33e4572

Browse files
committed
WIP: also complete device paths
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 97f5720 commit 33e4572

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cli/command/container/completion.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,24 @@ func completeDetachKeys(_ *cobra.Command, _ []string, _ string) ([]string, cobra
158158
// to provide completion for CDI devices that were discovered by the daemon.
159159
func completeCDIDevices(dockerCLI completion.APIClientProvider) cobra.CompletionFunc {
160160
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
161+
if strings.HasPrefix(toComplete, "/") {
162+
return nil, cobra.ShellCompDirectiveDefault | cobra.ShellCompDirectiveNoSpace
163+
}
164+
161165
info, err := dockerCLI.Client().Info(cmd.Context())
162166
if err != nil {
163-
return nil, cobra.ShellCompDirectiveError
167+
return nil, cobra.ShellCompDirectiveDefault
164168
}
165169
var devices []string
166170
// DiscoveredDevices requires Docker v28.2.0 (API 1.50) or above,
167171
// but we just check if it's returned.
168172
for _, di := range info.DiscoveredDevices {
169173
if di.Source == "cdi" {
170-
devices = append(devices, di.ID)
174+
devices = append(devices, cobra.CompletionWithDesc(di.ID, "CDI device"))
171175
}
172176
}
173-
return devices, cobra.ShellCompDirectiveNoFileComp
177+
devices = append(devices, "/")
178+
return devices, cobra.ShellCompDirectiveDefault
174179
}
175180
}
176181

0 commit comments

Comments
 (0)