feat: talosctl fish completion support

Generate talosctl completion for fish

Signed-off-by: Nico Berlee <nico.berlee@on2it.net>
Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
This commit is contained in:
Nico Berlee 2021-11-23 13:44:19 +01:00 committed by Andrey Smirnov
parent 6bb75150a3
commit 852bf4a7de
No known key found for this signature in database
GPG Key ID: 7B26396447AB6DFD
3 changed files with 19 additions and 8 deletions

View File

@ -16,8 +16,8 @@ import (
// completionCmd represents the completion command.
var completionCmd = &cobra.Command{
Use: "completion SHELL",
Short: "Output shell completion code for the specified shell (bash or zsh)",
Long: `Output shell completion code for the specified shell (bash or zsh).
Short: "Output shell completion code for the specified shell (bash, fish or zsh)",
Long: `Output shell completion code for the specified shell (bash, fish or zsh).
The shell code must be evaluated to provide interactive
completion of talosctl commands. This can be done by sourcing it from
the .bash_profile.
@ -44,11 +44,15 @@ Note for zsh users: [1] zsh completions are only supported in versions of zsh >=
source '$HOME/.talos/completion.bash.inc'
" >> $HOME/.bash_profile
source $HOME/.bash_profile
# Load the talosctl completion code for fish[1] into the current shell
talosctl completion fish | source
# Set the talosctl completion code for fish[1] to autoload on startup
talosctl completion fish > ~/.config/fish/completions/talosctl.fish
# Load the talosctl completion code for zsh[1] into the current shell
source <(talosctl completion zsh)
# Set the talosctl completion code for zsh[1] to autoload on startup
talosctl completion zsh > "${fpath[1]}/_talosctl"`,
ValidArgs: []string{"bash", "zsh"},
talosctl completion zsh > "${fpath[1]}/_talosctl"`,
ValidArgs: []string{"bash", "fish", "zsh"},
Args: cobra.ExactValidArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
@ -59,6 +63,8 @@ talosctl completion zsh > "${fpath[1]}/_talosctl"`,
switch args[0] {
case "bash":
return rootCmd.GenBashCompletion(os.Stdout)
case "fish":
return rootCmd.GenFishCompletion(os.Stdout, true)
case "zsh":
err := rootCmd.GenZshCompletion(os.Stdout)
// cobra does not hook the completion, so let's do it manually

View File

@ -24,6 +24,7 @@ func (suite *CompletionSuite) SuiteName() string {
// TestSuccess runs comand with success.
func (suite *CompletionSuite) TestSuccess() {
suite.RunCLI([]string{"completion", "bash"})
suite.RunCLI([]string{"completion", "fish"})
suite.RunCLI([]string{"completion", "zsh"})
}

View File

@ -253,11 +253,11 @@ A collection of commands for managing local docker-based or QEMU-based clusters
## talosctl completion
Output shell completion code for the specified shell (bash or zsh)
Output shell completion code for the specified shell (bash, fish or zsh)
### Synopsis
Output shell completion code for the specified shell (bash or zsh).
Output shell completion code for the specified shell (bash, fish or zsh).
The shell code must be evaluated to provide interactive
completion of talosctl commands. This can be done by sourcing it from
the .bash_profile.
@ -292,10 +292,14 @@ talosctl completion SHELL [flags]
source '$HOME/.talos/completion.bash.inc'
" >> $HOME/.bash_profile
source $HOME/.bash_profile
# Load the talosctl completion code for fish[1] into the current shell
talosctl completion fish | source
# Set the talosctl completion code for fish[1] to autoload on startup
talosctl completion fish > ~/.config/fish/completions/talosctl.fish
# Load the talosctl completion code for zsh[1] into the current shell
source <(talosctl completion zsh)
# Set the talosctl completion code for zsh[1] to autoload on startup
talosctl completion zsh > "${fpath[1]}/_talosctl"
talosctl completion zsh > "${fpath[1]}/_talosctl"
```
### Options
@ -2111,7 +2115,7 @@ A CLI for out-of-band management of Kubernetes nodes created by Talos
* [talosctl apply-config](#talosctl-apply-config) - Apply a new configuration to a node
* [talosctl bootstrap](#talosctl-bootstrap) - Bootstrap the etcd cluster on the specified node.
* [talosctl cluster](#talosctl-cluster) - A collection of commands for managing local docker-based or QEMU-based clusters
* [talosctl completion](#talosctl-completion) - Output shell completion code for the specified shell (bash or zsh)
* [talosctl completion](#talosctl-completion) - Output shell completion code for the specified shell (bash, fish or zsh)
* [talosctl config](#talosctl-config) - Manage the client configuration file (talosconfig)
* [talosctl conformance](#talosctl-conformance) - Run conformance tests
* [talosctl containers](#talosctl-containers) - List containers