Skip to content

Commit 91e90eb

Browse files
cbleckerjirfag
authored andcommitted
Add support for bash completions (#640)
1 parent 4ed1349 commit 91e90eb

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

pkg/commands/completion.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package commands
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func (e *Executor) initCompletion() {
11+
completionCmd := &cobra.Command{
12+
Use: "completion",
13+
Short: "Generates bash completion scripts",
14+
RunE: e.executeCompletion,
15+
}
16+
e.rootCmd.AddCommand(completionCmd)
17+
}
18+
19+
func (e *Executor) executeCompletion(cmd *cobra.Command, args []string) error {
20+
err := cmd.Root().GenBashCompletion(os.Stdout)
21+
if err != nil {
22+
return fmt.Errorf("unable to generate bash completions: %v", err)
23+
}
24+
25+
return nil
26+
}

pkg/commands/executor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func NewExecutor(version, commit, date string) *Executor {
7272
e.initHelp()
7373
e.initLinters()
7474
e.initConfig()
75+
e.initCompletion()
7576

7677
// init e.cfg by values from config: flags parse will see these values
7778
// like the default ones. It will overwrite them only if the same option

0 commit comments

Comments
 (0)