-
Notifications
You must be signed in to change notification settings - Fork 2k
context: add shell-completion for context-names #6016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cli/command/completion/functions.go
Outdated
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6016 +/- ##
==========================================
+ Coverage 58.88% 58.89% +0.01%
==========================================
Files 357 358 +1
Lines 29940 29961 +21
==========================================
+ Hits 17631 17647 +16
- Misses 11329 11333 +4
- Partials 980 981 +1 🚀 New features to boost your workflow:
|
cli/command/completion/functions.go
Outdated
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
cli/command/completion/functions.go
Outdated
names[i] += "\tcurrent" | ||
} | ||
} | ||
return names, cobra.ShellCompDirectiveNoFileComp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have "no space at end" option for positional arguments?
b04c106
to
1a7d7d6
Compare
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 |
Oh, actually; not sure that works; let's go with what we have here for now |
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
6fd72c6
Compare
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)