completeNames offers completion for plugin names in the given state. The state argument can be one of: - "all": all plugins - "enabled": all enabled plugins - "disabled": all disabled plugins
(dockerCLI completion.APIClientProvider, state pluginState)
| 21 | // - "enabled": all enabled plugins |
| 22 | // - "disabled": all disabled plugins |
| 23 | func completeNames(dockerCLI completion.APIClientProvider, state pluginState) cobra.CompletionFunc { |
| 24 | return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 25 | f := make(client.Filters) |
| 26 | switch state { |
| 27 | case stateEnabled: |
| 28 | f.Add("enabled", "true") |
| 29 | case stateDisabled: |
| 30 | f.Add("enabled", "false") |
| 31 | case stateAny: |
| 32 | // no filter |
| 33 | } |
| 34 | |
| 35 | res, err := dockerCLI.Client().PluginList(cmd.Context(), client.PluginListOptions{ |
| 36 | Filters: f, |
| 37 | }) |
| 38 | if err != nil { |
| 39 | return nil, cobra.ShellCompDirectiveError |
| 40 | } |
| 41 | var names []string |
| 42 | for _, v := range res.Items { |
| 43 | names = append(names, v.Name) |
| 44 | } |
| 45 | return names, cobra.ShellCompDirectiveNoFileComp |
| 46 | } |
| 47 | } |
no test coverage detected
searching dependent graphs…