MCPcopy Index your code
hub / github.com/docker/cli / completeContextNames

Function completeContextNames

cli/command/context/completion.go:21–46  ·  view source on GitHub ↗

completeContextNames implements shell completion for context-names. FIXME(thaJeztah): export, and remove duplicate of this function in cmd/docker.

(dockerCLI contextProvider, limit int, withFileComp bool)

Source from the content-addressed store, hash-verified

19//
20// FIXME(thaJeztah): export, and remove duplicate of this function in cmd/docker.
21func completeContextNames(dockerCLI contextProvider, limit int, withFileComp bool) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
22 return func(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
23 if limit > 0 && len(args) >= limit {
24 if withFileComp {
25 // Provide file/path completion after context name (for "docker context export")
26 return nil, cobra.ShellCompDirectiveDefault
27 }
28 return nil, cobra.ShellCompDirectiveNoFileComp
29 }
30
31 // TODO(thaJeztah): implement function similar to [store.Names] to (also) include descriptions.
32 names, _ := store.Names(dockerCLI.ContextStore())
33 out := make([]string, 0, len(names))
34 for _, name := range names {
35 if slices.Contains(args, name) {
36 // Already completed
37 continue
38 }
39 if name == dockerCLI.CurrentContext() {
40 name += "\tcurrent"
41 }
42 out = append(out, name)
43 }
44 return out, cobra.ShellCompDirectiveNoFileComp
45 }
46}

Callers 6

newExportCommandFunction · 0.70
newInspectCommandFunction · 0.70
newUpdateCommandFunction · 0.70
newRemoveCommandFunction · 0.70
newUseCommandFunction · 0.70
TestCompleteContextNamesFunction · 0.70

Calls 4

NamesMethod · 0.80
ContainsMethod · 0.80
ContextStoreMethod · 0.65
CurrentContextMethod · 0.65

Tested by 1

TestCompleteContextNamesFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…