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

Function completeNodeNames

cli/command/node/completion.go:16–37  ·  view source on GitHub ↗

completeNodeNames offers completion for swarm node (host)names and optional IDs. By default, only names are returned. Set DOCKER_COMPLETION_SHOW_NODE_IDS=yes to also complete IDs. TODO(thaJeztah): add support for filters.

(dockerCLI completion.APIClientProvider)

Source from the content-addressed store, hash-verified

14//
15// TODO(thaJeztah): add support for filters.
16func completeNodeNames(dockerCLI completion.APIClientProvider) cobra.CompletionFunc {
17 // https://github.com/docker/cli/blob/f9ced58158d5e0b358052432244b483774a1983d/contrib/completion/bash/docker#L41-L43
18 showIDs := os.Getenv("DOCKER_COMPLETION_SHOW_NODE_IDS") == "yes"
19 return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
20 res, err := dockerCLI.Client().NodeList(cmd.Context(), client.NodeListOptions{})
21 if err != nil {
22 return nil, cobra.ShellCompDirectiveError
23 }
24
25 names := make([]string, 0, len(res.Items)+1)
26 for _, node := range res.Items {
27 if showIDs {
28 names = append(names, node.Description.Hostname, node.ID)
29 } else {
30 names = append(names, node.Description.Hostname)
31 }
32 }
33 // Nodes allow "self" as magic word for the current node.
34 names = append(names, "self")
35 return names, cobra.ShellCompDirectiveNoFileComp
36 }
37}

Callers 6

newDemoteCommandFunction · 0.85
newInspectCommandFunction · 0.85
newUpdateCommandFunction · 0.85
newRemoveCommandFunction · 0.85
newPromoteCommandFunction · 0.85
newPsCommandFunction · 0.85

Calls 2

ClientMethod · 0.65
NodeListMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…