Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pkg/commands/completion.go
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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