Skip to content
Permalink
Browse files

Add support for bash completions (#640)

  • Loading branch information
cblecker authored and jirfag committed Sep 10, 2019
1 parent 4ed1349 commit 91e90eba6bfea44ee06f1413ba943d21659217e4
Showing with 27 additions and 0 deletions.
  1. +26 −0 pkg/commands/completion.go
  2. +1 −0 pkg/commands/executor.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
}
@@ -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

0 comments on commit 91e90eb

Please sign in to comment.
You can’t perform that action at this time.