Add support for bash completions (#640)

This commit is contained in:
Christoph Blecker 2019-09-10 01:30:02 -07:00 committed by Isaev Denis
parent 4ed1349a6b
commit 91e90eba6b
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package commands
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
func (e *Executor) initCompletion() {
completionCmd := &cobra.Command{
Use: "completion",
Short: "Generates bash completion scripts",
RunE: e.executeCompletion,
}
e.rootCmd.AddCommand(completionCmd)
}
func (e *Executor) executeCompletion(cmd *cobra.Command, args []string) error {
err := cmd.Root().GenBashCompletion(os.Stdout)
if err != nil {
return fmt.Errorf("unable to generate bash completions: %v", err)
}
return nil
}

View File

@ -72,6 +72,7 @@ func NewExecutor(version, commit, date string) *Executor {
e.initHelp()
e.initLinters()
e.initConfig()
e.initCompletion()
// init e.cfg by values from config: flags parse will see these values
// like the default ones. It will overwrite them only if the same option