Replace the current Zsh completion with a Zsh completion solution based
on Go completions. This allows to support custom completions (based
on Go completions), but also to standardize the behavior of completion
across all shells.
Also, add support to Go completions for the bash completion annotations:
BashCompFilenameExt (including Command.MarkFlagFilename() family)
- still supported by zsh
BashCompSubdirsInDir - now supported by zsh
BashCompOneRequiredFlag (including Command.MarkFlagRequired() family)
- now supported by zsh and fish
Finally, remove the suggestin of the = form of flag completion.
The = form is supported, but it will not be suggested to avoid having
duplicated suggestions.
* Don't exclude 'help' from bash completions
Fixes#1000.
* Provide completion for the help command
1- Show 'help' as a possible completion
2- Provide completions for the help command itself
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Co-authored-by: Zaven Muradyan <voithos@google.com>
Since the completion directives will be used for all shells, and that
these names will be consumed by users, this is a more appropriate name.
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
This commit allows programs using Cobra to code their custom completions
in Go instead of Bash.
The new ValidArgsFunction field is added for commands, similarly to
ValidArgs. For flags, the new function
Command.RegisterFlagCompletionFunc() is added.
When either of the above functions is used, the bash completion script
will call the new hidden command '__complete', passing it all
command-line arguments. The '__complete' command will call
the function specified by Command.ValidArgsFunction or by
Command.RegisterFlagCompletionFunc to obtain completions from the
program itself.
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>