completeEventFilters provides completion for the filters that can be used with `--filter`.
(dockerCLI completion.APIClientProvider)
| 86 | |
| 87 | // completeEventFilters provides completion for the filters that can be used with `--filter`. |
| 88 | func completeEventFilters(dockerCLI completion.APIClientProvider) cobra.CompletionFunc { |
| 89 | return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 90 | key, _, ok := strings.Cut(toComplete, "=") |
| 91 | if !ok { |
| 92 | return postfixWith("=", eventFilters), cobra.ShellCompDirectiveNoSpace |
| 93 | } |
| 94 | switch key { |
| 95 | case "container": |
| 96 | return prefixWith("container=", containerNames(dockerCLI, cmd, args, toComplete)), cobra.ShellCompDirectiveNoFileComp |
| 97 | case "daemon": |
| 98 | return prefixWith("daemon=", daemonNames(dockerCLI, cmd)), cobra.ShellCompDirectiveNoFileComp |
| 99 | case "event": |
| 100 | return prefixWith("event=", validEventNames()), cobra.ShellCompDirectiveNoFileComp |
| 101 | case "image": |
| 102 | return prefixWith("image=", imageNames(dockerCLI, cmd)), cobra.ShellCompDirectiveNoFileComp |
| 103 | case "label": |
| 104 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 105 | case "network": |
| 106 | return prefixWith("network=", networkNames(dockerCLI, cmd)), cobra.ShellCompDirectiveNoFileComp |
| 107 | case "node": |
| 108 | return prefixWith("node=", nodeNames(dockerCLI, cmd)), cobra.ShellCompDirectiveNoFileComp |
| 109 | case "scope": |
| 110 | return prefixWith("scope=", []string{"local", "swarm"}), cobra.ShellCompDirectiveNoFileComp |
| 111 | case "type": |
| 112 | return prefixWith("type=", eventTypeNames()), cobra.ShellCompDirectiveNoFileComp |
| 113 | case "volume": |
| 114 | return prefixWith("volume=", volumeNames(dockerCLI, cmd)), cobra.ShellCompDirectiveNoFileComp |
| 115 | default: |
| 116 | return postfixWith("=", eventFilters), cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // prefixWith prefixes every element in the slice with the given prefix. |
| 122 | func prefixWith(prefix string, values []string) []string { |
searching dependent graphs…