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

Function completeLinks

cli/command/container/completion.go:189–212  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

187// It contacts the API to get names of legacy links on containers.
188// In case of an error, an empty list is returned.
189func 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

Callers 2

newRmCommandFunction · 0.85
TestCompleteLinksFunction · 0.85

Calls 2

ClientMethod · 0.65
ContainerListMethod · 0.45

Tested by 1

TestCompleteLinksFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…