|
1 | 1 | package service |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "os" |
5 | | - |
6 | 4 | "github.com/docker/cli/cli" |
7 | 5 | "github.com/docker/cli/cli/command" |
8 | | - "github.com/docker/cli/cli/command/completion" |
9 | | - "github.com/docker/docker/api/types" |
10 | 6 | "github.com/spf13/cobra" |
11 | 7 | ) |
12 | 8 |
|
@@ -35,27 +31,3 @@ func NewServiceCommand(dockerCli command.Cli) *cobra.Command { |
35 | 31 | ) |
36 | 32 | return cmd |
37 | 33 | } |
38 | | - |
39 | | -// CompletionFn offers completion for swarm service names and optional IDs. |
40 | | -// By default, only names are returned. |
41 | | -// Set DOCKER_COMPLETION_SHOW_SERVICE_IDS=yes to also complete IDs. |
42 | | -func CompletionFn(dockerCLI completion.APIClientProvider) cobra.CompletionFunc { |
43 | | - // https://github.com/docker/cli/blob/f9ced58158d5e0b358052432244b483774a1983d/contrib/completion/bash/docker#L41-L43 |
44 | | - showIDs := os.Getenv("DOCKER_COMPLETION_SHOW_SERVICE_IDS") == "yes" |
45 | | - return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
46 | | - list, err := dockerCLI.Client().ServiceList(cmd.Context(), types.ServiceListOptions{}) |
47 | | - if err != nil { |
48 | | - return nil, cobra.ShellCompDirectiveError |
49 | | - } |
50 | | - |
51 | | - names := make([]string, 0, len(list)) |
52 | | - for _, service := range list { |
53 | | - if showIDs { |
54 | | - names = append(names, service.Spec.Name, service.ID) |
55 | | - } else { |
56 | | - names = append(names, service.Spec.Name) |
57 | | - } |
58 | | - } |
59 | | - return names, cobra.ShellCompDirectiveNoFileComp |
60 | | - } |
61 | | -} |
0 commit comments