completeLinks implements shell completion for the `--link` option of `rm --link`. It contacts the API to get names of legacy links on containers. In case of an error, an empty list is returned.
(dockerCLI completion.APIClientProvider)
| 187 | // It contacts the API to get names of legacy links on containers. |
| 188 | // In case of an error, an empty list is returned. |
| 189 | func completeLinks(dockerCLI completion.APIClientProvider) cobra.CompletionFunc { |
| 190 | return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 191 | res, err := dockerCLI.Client().ContainerList(cmd.Context(), client.ContainerListOptions{ |
| 192 | All: true, |
| 193 | }) |
| 194 | if err != nil { |
| 195 | return nil, cobra.ShellCompDirectiveError |
| 196 | } |
| 197 | var names []string |
| 198 | for _, ctr := range res.Items { |
| 199 | if len(ctr.Names) <= 1 { |
| 200 | // Container has no links names. |
| 201 | continue |
| 202 | } |
| 203 | for _, n := range ctr.Names { |
| 204 | // Skip legacy link names: "/linked-container/link-name" |
| 205 | if len(n) > 1 && strings.IndexByte(n[1:], '/') != -1 { |
| 206 | names = append(names, strings.TrimPrefix(n, "/")) |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | return names, cobra.ShellCompDirectiveNoFileComp |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | // completeLogDriver implements shell completion for the `--log-driver` option of `run` and `create`. |
| 215 | // The log drivers are collected from a call to the Info endpoint with a fallback to a hard-coded list |
searching dependent graphs…