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

Function completeServiceNames

cli/command/service/completion.go:14–33  ·  view source on GitHub ↗

completeServiceNames offers completion for swarm service names and optional IDs. By default, only names are returned. Set DOCKER_COMPLETION_SHOW_SERVICE_IDS=yes to also complete IDs.

(dockerCLI completion.APIClientProvider)

Source from the content-addressed store, hash-verified

12// By default, only names are returned.
13// Set DOCKER_COMPLETION_SHOW_SERVICE_IDS=yes to also complete IDs.
14func completeServiceNames(dockerCLI completion.APIClientProvider) cobra.CompletionFunc {
15 // https://github.com/docker/cli/blob/f9ced58158d5e0b358052432244b483774a1983d/contrib/completion/bash/docker#L41-L43
16 showIDs := os.Getenv("DOCKER_COMPLETION_SHOW_SERVICE_IDS") == "yes"
17 return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
18 res, err := dockerCLI.Client().ServiceList(cmd.Context(), client.ServiceListOptions{})
19 if err != nil {
20 return nil, cobra.ShellCompDirectiveError
21 }
22
23 names := make([]string, 0, len(res.Items))
24 for _, service := range res.Items {
25 if showIDs {
26 names = append(names, service.Spec.Name, service.ID)
27 } else {
28 names = append(names, service.Spec.Name)
29 }
30 }
31 return names, cobra.ShellCompDirectiveNoFileComp
32 }
33}

Callers 7

newLogsCommandFunction · 0.85
newInspectCommandFunction · 0.85
newUpdateCommandFunction · 0.85
newRemoveCommandFunction · 0.85
completeScaleArgsFunction · 0.85
newPsCommandFunction · 0.85
newRollbackCommandFunction · 0.85

Calls 2

ClientMethod · 0.65
ServiceListMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…