From 66a7cf26b323723da10d87b47f6c2973f1a0588b Mon Sep 17 00:00:00 2001 From: sayboras Date: Sun, 19 Apr 2020 16:30:50 +1000 Subject: [PATCH] Add fish auto completion --- cmd/minikube/cmd/completion.go | 31 ++++++++++++++++++--- go.mod | 2 +- go.sum | 9 ++++++ site/content/en/docs/commands/completion.md | 9 ++++-- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/cmd/minikube/cmd/completion.go b/cmd/minikube/cmd/completion.go index 5c0669d3cde6..5320ed165b71 100644 --- a/cmd/minikube/cmd/completion.go +++ b/cmd/minikube/cmd/completion.go @@ -28,7 +28,7 @@ import ( ) const longDescription = ` - Outputs minikube shell completion for the given shell (bash or zsh) + Outputs minikube shell completion for the given shell (bash, zsh or fish) This depends on the bash-completion binary. Example installation instructions: OS X: @@ -37,15 +37,18 @@ const longDescription = ` $ minikube completion bash > ~/.minikube-completion # for bash users $ minikube completion zsh > ~/.minikube-completion # for zsh users $ source ~/.minikube-completion + $ minikube completion fish > ~/.config/fish/completions/minikube.fish # for fish users Ubuntu: $ apt-get install bash-completion $ source /etc/bash-completion $ source <(minikube completion bash) # for bash users $ source <(minikube completion zsh) # for zsh users + $ minikube completion fish > ~/.config/fish/completions/minikube.fish # for fish users Additionally, you may want to output the completion to a file and source in your .bashrc Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2 + Note for fish users: [2] please refer to this docs for more details https://fishshell.com/docs/current/#tab-completion ` const boilerPlate = ` @@ -66,24 +69,29 @@ const boilerPlate = ` var completionCmd = &cobra.Command{ Use: "completion SHELL", - Short: "Outputs minikube shell completion for the given shell (bash or zsh)", + Short: "Outputs minikube shell completion for the given shell (bash, zsh or fish)", Long: longDescription, Run: func(cmd *cobra.Command, args []string) { if len(args) != 1 { exit.UsageT("Usage: minikube completion SHELL") } - if args[0] != "bash" && args[0] != "zsh" { + if args[0] != "bash" && args[0] != "zsh" && args[0] != "fish" { exit.UsageT("Sorry, completion support is not yet implemented for {{.name}}", out.V{"name": args[0]}) } else if args[0] == "bash" { err := GenerateBashCompletion(os.Stdout, cmd.Parent()) if err != nil { exit.WithError("bash completion failed", err) } - } else { + } else if args[0] == "zsh" { err := GenerateZshCompletion(os.Stdout, cmd.Parent()) if err != nil { exit.WithError("zsh completion failed", err) } + } else { + err := GenerateFishCompletion(os.Stdout, cmd.Parent()) + if err != nil { + exit.WithError("fish completion failed", err) + } } }, @@ -279,3 +287,18 @@ __minikube_bash_source <(__minikube_convert_bash_to_zsh) return nil } + +// GenerateBashCompletion generates the completion for the bash shell +func GenerateFishCompletion(w io.Writer, cmd *cobra.Command) error { + _, err := w.Write([]byte(boilerPlate)) + if err != nil { + return err + } + + err = cmd.GenFishCompletion(w, true) + if err != nil { + return errors.Wrap(err, "Error generating fish completion") + } + + return nil +} diff --git a/go.mod b/go.mod index 62c03dbf0019..e8000701b03f 100644 --- a/go.mod +++ b/go.mod @@ -70,7 +70,7 @@ require ( github.com/samalba/dockerclient v0.0.0-20160414174713-91d7393ff859 // indirect github.com/shirou/gopsutil v2.18.12+incompatible github.com/spf13/cast v1.3.1 // indirect - github.com/spf13/cobra v0.0.5 + github.com/spf13/cobra v1.0.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.6.1 github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect diff --git a/go.sum b/go.sum index d9235acee968..e515f17ba511 100644 --- a/go.sum +++ b/go.sum @@ -156,6 +156,8 @@ github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea/go.mod h1:E3G3o1h8I7cfc github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/cyphar/filepath-securejoin v0.2.2 h1:jCwT2GTP+PY5nBz3c/YL5PAIbusElVrPujOBSCj8xRg= 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 github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday v1.5.3-0.20200218234912-41c5fccfd6f6 h1:tlXG832s5pa9x9Gs3Rp2rTvEqjiDEuETUOSfBEiTcns= github.com/russross/blackfriday v1.5.3-0.20200218234912-41c5fccfd6f6/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= 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 github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc= github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= 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 github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= +github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= 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 github.com/spf13/viper v1.0.2/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM= github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/spf13/viper v1.6.1 h1:VPZzIkznI1YhVMRi6vNFLHSwhnhReBfgTxIPccpfdZk= github.com/spf13/viper v1.6.1/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= github.com/storageos/go-api v0.0.0-20180912212459-343b3eff91fc/go.mod h1:ZrLn+e0ZuF3Y65PNF6dIwbJPZqfmtCXxFm9ckv0agOY= diff --git a/site/content/en/docs/commands/completion.md b/site/content/en/docs/commands/completion.md index 38bec1731833..8557cc068b0a 100644 --- a/site/content/en/docs/commands/completion.md +++ b/site/content/en/docs/commands/completion.md @@ -1,19 +1,19 @@ --- title: "completion" description: > - Outputs minikube shell completion for the given shell (bash or zsh) + Outputs minikube shell completion for the given shell (bash, zsh or fish) --- ## minikube completion -Outputs minikube shell completion for the given shell (bash or zsh) +Outputs minikube shell completion for the given shell (bash, zsh or fish) ### Synopsis - Outputs minikube shell completion for the given shell (bash or zsh) + Outputs minikube shell completion for the given shell (bash, zsh or fish) This depends on the bash-completion binary. Example installation instructions: OS X: @@ -22,15 +22,18 @@ Outputs minikube shell completion for the given shell (bash or zsh) $ minikube completion bash > ~/.minikube-completion # for bash users $ minikube completion zsh > ~/.minikube-completion # for zsh users $ source ~/.minikube-completion + $ minikube completion fish > ~/.config/fish/completions/minikube.fish # for fish users Ubuntu: $ apt-get install bash-completion $ source /etc/bash-completion $ source <(minikube completion bash) # for bash users $ source <(minikube completion zsh) # for zsh users + $ minikube completion fish > ~/.config/fish/completions/minikube.fish # for fish users Additionally, you may want to output the completion to a file and source in your .bashrc Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2 + Note for fish users: [2] please refer to this docs for more details https://fishshell.com/docs/current/#tab-completion ```