Skip to content

Commit d822303

Browse files
authored
feat: fish completion
1 parent bf9b048 commit d822303

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

cmd/completion.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func init() {
1313

1414
// completionCmd represents the completion command
1515
var completionCmd = &cobra.Command{
16-
Use: "completion <bash|zsh>",
16+
Use: "completion <bash|zsh|fish>",
1717
Short: "Generate bash/zsh completion scripts",
1818
Long: `To load completion run
1919
@@ -28,20 +28,23 @@ For bash:
2828
source <(faas completion bash)
2929
3030
`,
31-
ValidArgs: []string{"bash", "zsh"},
31+
ValidArgs: []string{"bash", "zsh", "fish"},
3232
Args: cobra.ExactArgs(1),
3333
RunE: func(cmd *cobra.Command, args []string) (err error) {
3434
if len(args) < 1 {
3535
return errors.New("missing argument")
3636
}
37-
if args[0] == "bash" {
37+
switch args[0] {
38+
case "bash":
3839
err = root.GenBashCompletion(os.Stdout)
39-
return err
40-
}
41-
if args[0] == "zsh" {
40+
case "zsh":
4241
err = root.GenZshCompletion(os.Stdout)
43-
return err
42+
case "fish":
43+
err = root.GenFishCompletion(os.Stdout, true)
44+
default:
45+
err = errors.New("unknown shell, only bash, zsh and fish are supported")
4446
}
45-
return errors.New("unknown shell, only bash and zsh are supported")
47+
48+
return err
4649
},
4750
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/markbates/pkger v0.17.0
88
github.com/mitchellh/go-homedir v1.1.0
99
github.com/ory/viper v1.7.4
10-
github.com/spf13/cobra v1.0.1-0.20200715031239-b95db644ed1c
10+
github.com/spf13/cobra v1.0.1-0.20201006035406-b97b5ead31f7
1111
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect
1212
gopkg.in/yaml.v2 v2.3.0
1313
k8s.io/api v0.18.8

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,8 @@ github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHN
11751175
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
11761176
github.com/spf13/cobra v1.0.1-0.20200715031239-b95db644ed1c h1:nt+V0u9zwtHQLk4OrQxVDMwJ7ifwoUzqcrcxySbmxxY=
11771177
github.com/spf13/cobra v1.0.1-0.20200715031239-b95db644ed1c/go.mod h1:yk5b0mALVusDL5fMM6Rd1wgnoO5jUPhwsQ6LQAJTidQ=
1178+
github.com/spf13/cobra v1.0.1-0.20201006035406-b97b5ead31f7 h1:O63eWlXlvyw4YdsuatjRIU6emvJ2fqz+PTdMEoxIT2s=
1179+
github.com/spf13/cobra v1.0.1-0.20201006035406-b97b5ead31f7/go.mod h1:yk5b0mALVusDL5fMM6Rd1wgnoO5jUPhwsQ6LQAJTidQ=
11781180
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
11791181
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
11801182
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=

0 commit comments

Comments
 (0)