completeContextNames implements shell completion for context-names. FIXME(thaJeztah): export, and remove duplicate of this function in cmd/docker.
(dockerCLI contextProvider, limit int, withFileComp bool)
| 19 | // |
| 20 | // FIXME(thaJeztah): export, and remove duplicate of this function in cmd/docker. |
| 21 | func completeContextNames(dockerCLI contextProvider, limit int, withFileComp bool) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) { |
| 22 | return func(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 23 | if limit > 0 && len(args) >= limit { |
| 24 | if withFileComp { |
| 25 | // Provide file/path completion after context name (for "docker context export") |
| 26 | return nil, cobra.ShellCompDirectiveDefault |
| 27 | } |
| 28 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 29 | } |
| 30 | |
| 31 | // TODO(thaJeztah): implement function similar to [store.Names] to (also) include descriptions. |
| 32 | names, _ := store.Names(dockerCLI.ContextStore()) |
| 33 | out := make([]string, 0, len(names)) |
| 34 | for _, name := range names { |
| 35 | if slices.Contains(args, name) { |
| 36 | // Already completed |
| 37 | continue |
| 38 | } |
| 39 | if name == dockerCLI.CurrentContext() { |
| 40 | name += "\tcurrent" |
| 41 | } |
| 42 | out = append(out, name) |
| 43 | } |
| 44 | return out, cobra.ShellCompDirectiveNoFileComp |
| 45 | } |
| 46 | } |
searching dependent graphs…