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>
* 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