1
1
package commands
2
2
3
3
import (
4
+ "fmt"
4
5
"os"
5
6
6
7
"github.com/pkg/errors"
@@ -17,16 +18,36 @@ func (e *Executor) initCompletion() {
17
18
bashCmd := & cobra.Command {
18
19
Use : "bash" ,
19
20
Short : "Output bash completion script" ,
20
- RunE : e .executeCompletion ,
21
+ RunE : e .executeBashCompletion ,
21
22
}
22
23
completionCmd .AddCommand (bashCmd )
24
+
25
+ zshCmd := & cobra.Command {
26
+ Use : "zsh" ,
27
+ Short : "Output zsh completion script" ,
28
+ RunE : e .executeZshCompletion ,
29
+ }
30
+ completionCmd .AddCommand (zshCmd )
23
31
}
24
32
25
- func (e * Executor ) executeCompletion (cmd * cobra.Command , args []string ) error {
33
+ func (e * Executor ) executeBashCompletion (cmd * cobra.Command , args []string ) error {
26
34
err := cmd .Root ().GenBashCompletion (os .Stdout )
27
35
if err != nil {
28
36
return errors .Wrap (err , "unable to generate bash completions: %v" )
29
37
}
30
38
31
39
return nil
32
40
}
41
+
42
+ func (e * Executor ) executeZshCompletion (cmd * cobra.Command , args []string ) error {
43
+ err := cmd .Root ().GenZshCompletion (os .Stdout )
44
+ if err != nil {
45
+ return errors .Wrap (err , "unable to generate zsh completions: %v" )
46
+ }
47
+ // Add extra compdef directive to support sourcing command directly.
48
+ // https://github.com/spf13/cobra/issues/881
49
+ // https://github.com/spf13/cobra/pull/887
50
+ fmt .Println ("compdef _golangci-lint golangci-lint" )
51
+
52
+ return nil
53
+ }
0 commit comments