File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package cmd
2+
3+ import (
4+ "fmt"
5+ "os"
6+
7+ "github.com/spf13/cobra"
8+ )
9+
10+ func (k * KsctlCommand ) ShellCompletion () * cobra.Command {
11+ cmd := & cobra.Command {
12+ Use : "completion [bash|zsh|fish]" ,
13+ Short : "Generate shell completion scripts" ,
14+ Long : `To load completions:
15+
16+ Bash:
17+
18+ $ source <(ksctl completion bash)
19+
20+ # To load completions for each session, execute once:
21+ # Linux:
22+ $ ksctl completion bash > /etc/bash_completion.d/ksctl
23+ # macOS:
24+ $ ksctl completion bash > /usr/local/etc/bash_completion.d/ksctl
25+
26+ Zsh:
27+
28+ $ echo "autoload -U compinit; compinit" >> ~/.zshrc
29+ $ ksctl completion zsh > "${fpath[1]}/_ksctl"
30+
31+ Fish:
32+
33+ $ ksctl completion fish | source
34+
35+ # To load completions for each session, execute once:
36+ $ ksctl completion fish > ~/.config/fish/completions/ksctl.fish
37+ ` ,
38+ Args : cobra .ExactArgs (1 ),
39+ RunE : func (cmd * cobra.Command , args []string ) error {
40+ switch args [0 ] {
41+ case "bash" :
42+ return cmd .Root ().GenBashCompletion (os .Stdout )
43+ case "zsh" :
44+ return cmd .Root ().GenZshCompletion (os .Stdout )
45+ case "fish" :
46+ return cmd .Root ().GenFishCompletion (os .Stdout , true )
47+ default :
48+ return fmt .Errorf ("unsupported shell: %s" , args [0 ])
49+ }
50+ },
51+ }
52+
53+ return cmd
54+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ func (k *KsctlCommand) CommandMapping() error {
2626 c ,
2727 k .Version (),
2828 k .SelfUpdate (),
29+ k .ShellCompletion (),
2930 cr ,
3031 )
3132 cli .RegisterCommand (
You can’t perform that action at this time.
0 commit comments