Add --init-completion flag to print completion code

This flag takes as input 'bash' or 'zsh' and generates the completion
code for the specified shell.
This commit is contained in:
Antoine Eiche
2016-07-21 21:01:59 +02:00
parent ee2e8aa5b2
commit 7640bef0eb
3 changed files with 50 additions and 0 deletions

6
app.go
View File

@@ -138,6 +138,7 @@ func (a *App) Setup() {
if a.EnableBashCompletion {
a.appendFlag(BashCompletionFlag)
a.appendFlag(InitCompletionFlag)
}
if !a.HideVersion {
@@ -176,6 +177,11 @@ func (a *App) Run(arguments []string) (err error) {
return nil
}
var done bool
if done, err = checkInitCompletion(context); done {
return nil
}
if err != nil {
if a.OnUsageError != nil {
err := a.OnUsageError(context, err, false)