Skip to content

Commit

Permalink
feat: talosctl fish completion support
Browse files Browse the repository at this point in the history
Generate talosctl completion for fish

Signed-off-by: Nico Berlee <nico.berlee@on2it.net>
Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
nberlee authored and smira committed Nov 23, 2021
1 parent 6bb7515 commit 852bf4a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
14 changes: 10 additions & 4 deletions cmd/talosctl/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/integration/cli/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
}

Expand Down
12 changes: 8 additions & 4 deletions website/content/docs/v0.14/Reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 852bf4a

Please sign in to comment.