Add support for bash completions (#640)
This commit is contained in:
parent
4ed1349a6b
commit
91e90eba6b
26
pkg/commands/completion.go
Normal file
26
pkg/commands/completion.go
Normal 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
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user