Commit Graph

16 Commits

Author SHA1 Message Date
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
Daisuke Taniwaki d2d81d9a96 Fix too many underscore for __custom_func (#794)
* Fix too many underscore for __custom_func

* Fix typo of too many leading underscores in docs
2018-11-27 08:31:06 -05:00
Paul 6fd8e29b07 Qualify custom bash func name (#730)
* Qualify custom bash func name

 - fixes issue where multiple cobra apps using custom bash completion
 would have their __custom_func collide
 - support fallback to plain __custom_func to maintain compatibility

#694

* Improve tests for bash completion __custom_func

 - check for the correct number of occurrences of function name

#694
2018-08-21 12:12:02 -04:00
Jason Hendry 1e58aa3361 Include a basic example #465 (#631) 2018-05-31 14:03:38 -04:00
Zef Hemel ef82de70bb Fixed code sample for bash completion (#687) 2018-04-27 09:45:50 -04:00
Bilal Amarni c6c44e6fdc Update the bash completion example for kubectl (#645) 2018-03-01 10:15:57 -08:00
Rajat Jindal a1e4933ab7 Bash completion aliases (#638)
* alias support with bash completions

* add cmdname to rootcmdname

* remove print statement

* add documentation for bash alias
2018-02-21 09:51:53 -08:00
Ryan Guest f91529fc60 Fix a couple typos (#621) 2018-01-24 08:31:43 +01:00
G. Hussain Chinoy 4673102358 Updating bash_completions to clarify markdown (#442)
"Plural form and shortcuts for nouns" section had a stray backtick, making Markdown rendering for code examples strange. Removed said backtick.
2017-05-11 17:04:35 +02:00
Apurva Chitnis dc208f4211 Added useful info for setting up bash autocompletion. (#384) 2017-01-18 13:55:16 -05:00
joe2far 719241171d Fixed typos in README and docstring 2016-06-07 11:50:48 +01:00
Dr. Stefan Schimanski 1a0a490d76 Remove plural handling and add aliases for nouns in completion 2016-04-02 12:39:19 +02:00
Dr. Stefan Schimanski 8092588fb8 Add custom bash flag completion 2016-03-21 08:05:54 +01:00
Scott Konzem 39e648c2b0 Fix typos in docs 2015-06-05 13:02:54 -04:00
Eric Paris 48b95d0594 Make the filename extension bit of docs easier to read. 2015-05-04 16:20:06 -04:00
Eric Paris 9b2e6822e5 Add bash autocompletion generator
Given a (potentially annotated) cobra command you can generate a bash
completion script.
2015-04-07 20:13:49 -04:00