Skip to content

Commit

Permalink
Add support for bash completions (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
cblecker authored and jirfag committed Sep 10, 2019
1 parent 4ed1349 commit 91e90eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/commands/completion.go
@@ -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
}
1 change: 1 addition & 0 deletions pkg/commands/executor.go
Expand Up @@ -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
Expand Down

0 comments on commit 91e90eb

Please sign in to comment.