Commit Graph

9 Commits

Author SHA1 Message Date
Unai Martinez-Corral
652c755d37
Use golangci-lint (#1044)
Use golangci-lint. Repair warnings and errors resulting from linting.
2021-02-07 17:08:50 -07:00
Luap99
8a63648dd9
Handle linebreaks in custom completions. (#1162)
If a command/flag description contains
a linebreak then the shell completion script
will interpret this as new command/flag.

To fix this we only use the first line
from the description in the output.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2020-09-09 11:27:42 -06:00
Luap99
50258f15eb
Complete subcommands when TraverseChildren is set (#1171)
* Complete subcommands when TraverseChildren is true in custom completion

The current custom completion logic does not complete
subcommands when a local flag is set. This is good unless
TraverseChildren is set to true where local flags
can be set on parent commands.

This commit allows subcommands to be completed
if TraverseChildren is set to true on the root cmd.

Closes #1170

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>

* Complete subcommands when TraverseChildren is true in bash completion

The current bash completion logic does not complete
subcommands when a local flag is set. There is also a bug
where subcommands are sometimes still getting completed. see: #1172

If TraverseChildren is true we should allow subcommands
to be completed even if a local flag is set.

Closes #1172

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2020-09-09 09:34:51 -06:00
Marc Khouzam
675ae5f5a9
Fish does not accept - or : in vars (#1122)
Fixes #1121.
This is for programs that may contain a : or - in their name.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2020-07-10 14:12:46 -06:00
Marc Khouzam
2c5a0d300f
Extend Go completions and revamp zsh comp (#1070) (#1070)
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.
2020-06-29 13:52:14 -06:00
Marc Khouzam
04318720db
Add completion for help command (#1136)
* 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>
2020-06-16 14:49:26 -06:00
Marc Khouzam
a684a6d7f5
Fish completion using Go completion (#1048)
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2020-04-10 13:56:28 -06:00
Marc Khouzam
b84ef40338
Rename BashCompDirectives to ShellCompDirectives (#1082)
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>
2020-04-06 11:28:44 -06:00
Marc Khouzam
b80aeb17fc
Add support for custom completions in Go (#1035)
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>
2020-04-03 13:43:43 -06:00