Uh oh!
There was an error while loading. Please reload this page.
context: add shell-completion for context-names - #6016
Conversation
| "github.com/docker/cli/cli/command/formatter" | ||
| "github.com/docker/cli/cli/context/store" | ||
| "github.com/docker/docker/api/types/container" | ||
| "github.com/docker/docker/api/types/image" | ||
| "github.com/docker/docker/api/types/network" |
There was a problem hiding this comment.
Starting to consider if we should have sub-packages here, otherwise cli/command/completion will pull in too many other packages. We can either use cli/command/completion/xxx or alternatively, per command (cli/command/container/completion). Or .. maybe it should live elsewhere 🤔
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
| // ContextNames implements shell completion for context-names. | ||
| func ContextNames(dockerCLI contextProvider) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) { | ||
| return func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) { | ||
| // TODO(thaJeztah): implement function similar to [store.Names] to (also) include descriptions. | ||
| names, _ := store.Names(dockerCLI.ContextStore()) |
There was a problem hiding this comment.
Missing some options here to differentiate for different commands;
- some only accept a single arg
- some should not include the current context (probably)
- ideally, we'd be able to also add the context's description (which could be useful, if short that is)
| names[i] += "\tcurrent" | ||
| } | ||
| } | ||
| return names, cobra.ShellCompDirectiveNoFileComp |
There was a problem hiding this comment.
Should we have "no space at end" option for positional arguments?
b04c106 to
1a7d7d6ComparethaJeztah
commented
Apr 17, 2025
I have one more small enhancement to not add a space after the limit is reached (and we don't use file-completion after it); let me push |
thaJeztah
commented
Apr 17, 2025
Oh, actually; not sure that works; let's go with what we have here for now |
Uh oh!
There was an error while loading. Please reload this page.
For now, these are not exported and included in the cli/commands/contexts package; a copy of this also lives in cmd/docker, but we need to find a good place for these completions, as some of them bring in additional dependencies. Commands that accept multiple arguments provide completion, but removing duplicates: docker context inspect<TAB> default desktop-linux (current) production tcd docker context inspec default<TAB> desktop-linux (current) production tcd docker context inspect default tcd<TAB> desktop-linux (current) production For "context export", we provide completion for the first argument, after which file-completion is provided: # provides context names completion for the first argument docker context export production<TAB> default desktop-linux (current) production tcd # then provides completion for filenames docker context export desktop-linux<TAB> build/ man/ TESTING.md cli/ docker.Makefile go.mod ... Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1a7d7d6 to
6fd72c6Compare| // FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16: | ||
| //go:build go1.22 |
There was a problem hiding this comment.
Note to self; need to update #5868 after this is merged.
For now, these are not exported and included in the cli/commands/contexts
package; a copy of this also lives in cmd/docker, but we need to find a
good place for these completions, as some of them bring in additional
dependencies.
Commands that accept multiple arguments provide completion, but removing
duplicates:
For "context export", we provide completion for the first argument, after
which file-completion is provided:
- What I did
- How I did it
- How to verify it
- Human readable description for the release notes
- A picture of a cute animal (not mandatory but encouraged)