Skip to content

Commit fb1a39b

Browse files
committed
Add fish completion support
1 parent af98f75 commit fb1a39b

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

Diff for: cmd/minikube/cmd/completion.go

+24-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
const longDescription = `
31-
Outputs minikube shell completion for the given shell (bash or zsh)
31+
Outputs minikube shell completion for the given shell (bash, zsh or fish)
3232
3333
This depends on the bash-completion binary. Example installation instructions:
3434
OS X:
@@ -46,6 +46,7 @@ const longDescription = `
4646
Additionally, you may want to output the completion to a file and source in your .bashrc
4747
4848
Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2
49+
Note for fish users: [2] please refer to this docs for more details https://fishshell.com/docs/current/#tab-completion
4950
`
5051

5152
const boilerPlate = `
@@ -72,18 +73,23 @@ var completionCmd = &cobra.Command{
7273
if len(args) != 1 {
7374
exit.UsageT("Usage: minikube completion SHELL")
7475
}
75-
if args[0] != "bash" && args[0] != "zsh" {
76+
if args[0] != "bash" && args[0] != "zsh" && args[0] != "fish" {
7677
exit.UsageT("Sorry, completion support is not yet implemented for {{.name}}", out.V{"name": args[0]})
7778
} else if args[0] == "bash" {
7879
err := GenerateBashCompletion(os.Stdout, cmd.Parent())
7980
if err != nil {
8081
exit.WithError("bash completion failed", err)
8182
}
82-
} else {
83+
} else if args[0] == "zsh" {
8384
err := GenerateZshCompletion(os.Stdout, cmd.Parent())
8485
if err != nil {
8586
exit.WithError("zsh completion failed", err)
8687
}
88+
} else {
89+
err := GenerateFishCompletion(os.Stdout, cmd.Parent())
90+
if err != nil {
91+
exit.WithError("zsh completion failed", err)
92+
}
8793
}
8894

8995
},
@@ -279,3 +285,18 @@ __minikube_bash_source <(__minikube_convert_bash_to_zsh)
279285

280286
return nil
281287
}
288+
289+
// GenerateBashCompletion generates the completion for the bash shell
290+
func GenerateFishCompletion(w io.Writer, cmd *cobra.Command) error {
291+
_, err := w.Write([]byte(boilerPlate))
292+
if err != nil {
293+
return err
294+
}
295+
296+
err = cmd.GenFishCompletion(w, true)
297+
if err != nil {
298+
return errors.Wrap(err, "Error generating fish completion")
299+
}
300+
301+
return nil
302+
}

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ require (
7070
github.com/samalba/dockerclient v0.0.0-20160414174713-91d7393ff859 // indirect
7171
github.com/shirou/gopsutil v2.18.12+incompatible
7272
github.com/spf13/cast v1.3.1 // indirect
73-
github.com/spf13/cobra v0.0.5
73+
github.com/spf13/cobra v1.0.0
7474
github.com/spf13/pflag v1.0.5
7575
github.com/spf13/viper v1.6.1
7676
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect

Diff for: go.sum

+9
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea/go.mod h1:E3G3o1h8I7cfc
156156
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
157157
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
158158
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
159+
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
160+
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
159161
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
160162
github.com/cyphar/filepath-securejoin v0.2.2 h1:jCwT2GTP+PY5nBz3c/YL5PAIbusElVrPujOBSCj8xRg=
161163
github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
@@ -706,6 +708,8 @@ github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNue
706708
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
707709
github.com/russross/blackfriday v1.5.3-0.20200218234912-41c5fccfd6f6 h1:tlXG832s5pa9x9Gs3Rp2rTvEqjiDEuETUOSfBEiTcns=
708710
github.com/russross/blackfriday v1.5.3-0.20200218234912-41c5fccfd6f6/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
711+
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
712+
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
709713
github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
710714
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
711715
github.com/sayboras/dockerclient v0.0.0-20191231050035-015626177a97 h1:DWY4yZN6w+FSKMeqBBXaalT8zmCn4DVwBGopShnlwFE=
@@ -722,6 +726,8 @@ github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+D
722726
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
723727
github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
724728
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ=
729+
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
730+
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
725731
github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
726732
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
727733
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
@@ -750,6 +756,8 @@ github.com/spf13/cobra v0.0.2/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3
750756
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
751757
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
752758
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
759+
github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8=
760+
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
753761
github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
754762
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
755763
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
@@ -764,6 +772,7 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
764772
github.com/spf13/viper v1.0.2/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM=
765773
github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M=
766774
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
775+
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
767776
github.com/spf13/viper v1.6.1 h1:VPZzIkznI1YhVMRi6vNFLHSwhnhReBfgTxIPccpfdZk=
768777
github.com/spf13/viper v1.6.1/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k=
769778
github.com/storageos/go-api v0.0.0-20180912212459-343b3eff91fc/go.mod h1:ZrLn+e0ZuF3Y65PNF6dIwbJPZqfmtCXxFm9ckv0agOY=

Diff for: site/content/en/docs/commands/completion.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Outputs minikube shell completion for the given shell (bash or zsh)
1313
### Synopsis
1414

1515

16-
Outputs minikube shell completion for the given shell (bash or zsh)
16+
Outputs minikube shell completion for the given shell (bash, zsh or fish)
1717

1818
This depends on the bash-completion binary. Example installation instructions:
1919
OS X:
@@ -31,6 +31,7 @@ Outputs minikube shell completion for the given shell (bash or zsh)
3131
Additionally, you may want to output the completion to a file and source in your .bashrc
3232

3333
Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2
34+
Note for fish users: [2] please refer to this docs for more details https://fishshell.com/docs/current/#tab-completion
3435

3536

3637
```

0 commit comments

Comments
 (0)