-
Notifications
You must be signed in to change notification settings - Fork 66
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
feat(cmd): added command to generate basic cmd autocompletion scripts #1240
Conversation
Depends on #1242 and will also require updates/new flags for some commands to have easily digestable output for shell scripts. |
Depends on #1247 |
Also just to be complete on the evolution of this, here's a list of commands (not exhausitve, but almost) which I'll update and reflect on depending on the case. Flags are still the odd case I don't handle here and not sure if I'll completely cover it in just this PR. No dependencies:
Depends on qri search:
Depends on qri list:
Will not cover now (reason):
|
Another consideration would be to ship pre-generated autocomplete files so you can just For more input refer to the above comment on the specific functionality. |
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.
Ok just ran this, so nice.
I think we'll need a few passes of fitting & cleanup–as you've noted there are additional commands not yet covered by this PR–but those can come in time. As an example qri get ... <tab>
lists dataset names (yay!), but kinda obfuscates qri get body <tab>
. Don't know if or how we want to handle that scenario.
All that said, wow do completions make life on the CLI easier. The benefits of autocompletion far outweigh any quirks.
cmd/completion.go
Outdated
o := &AutocompleteOptions{IOStreams: ioStreams} | ||
cmd := &cobra.Command{ | ||
Use: "completion [bash|zsh]", | ||
Short: "Generates shell completion scripts", |
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.
keeping with our CLI Help Style, should be generate shell auto-completion scripts
RunE: func(cmd *cobra.Command, args []string) error { | ||
return o.Run(cmd, args) | ||
}, | ||
ValidArgs: []string{"bash", "zsh"}, |
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.
Let's add the Annotations
field to make this show up in qri --help
:
Annotations: map[string]string{
"group": "other",
}
cmd/completion.go
Outdated
Short: "Generates shell completion scripts", | ||
Long: `To load completion run | ||
|
||
source <(qri completion [bash|zsh]) |
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.
add a $
for anything the user should type, and consider moving these into the Examples
field.
Yeah, there's still quite a bit of work to do to have it complete, but did my best to document the things that work and that don't. For the specific example with Anyways, my intention was to keep the original issue alive and have it document the missing pieces so we can pick it up again later. |
Relevant to #1236
Took a mix of inspiration between
cobra
docs andkubectl
handling ofzsh
support.Currently it only handles registered commands and flags, no support for dataset name autocomplete just yet.
The convoluted approach for
zsh
is due tocobra
not supporting "advanced/custom" autocomplete functions and thus would not work for the future dataset name autocompletion (or similar scenarios like peers etc).