Skip to content

Commit 89f3183

Browse files
Add completion command
1 parent 68dbecb commit 89f3183

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,35 @@ var cmdVersion = &cobra.Command{
2828
},
2929
}
3030

31+
var completionCmd = &cobra.Command{
32+
Use: "completion [bash|zsh|fish|powershell]",
33+
Short: "Generate completion script",
34+
Long: "To load completions",
35+
DisableFlagsInUseLine: true,
36+
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
37+
Args: cobra.ExactValidArgs(1),
38+
Run: func(cmd *cobra.Command, args []string) {
39+
switch args[0] {
40+
case "bash":
41+
cmdRoot.GenBashCompletionV2(os.Stdout, true)
42+
case "zsh":
43+
cmdRoot.GenZshCompletion(os.Stdout)
44+
case "fish":
45+
cmdRoot.GenFishCompletion(os.Stdout, true)
46+
case "powershell":
47+
cmdRoot.GenPowerShellCompletionWithDesc(os.Stdout)
48+
}
49+
},
50+
}
51+
3152
func init() {
3253
// configure cobra help texts
3354
setupHelp(cmdRoot)
3455
fuzz.AddCommand(cmdRoot)
3556
show.AddCommand(cmdRoot)
3657
list.AddCommand(cmdRoot)
3758
cmdRoot.AddCommand(cmdVersion)
59+
cmdRoot.AddCommand(completionCmd)
3860
}
3961

4062
func injectDefaultCommand(args []string) []string {

0 commit comments

Comments
 (0)