Skip to content

Commit

Permalink
Add completion command
Browse files Browse the repository at this point in the history
  • Loading branch information
rtpt-romankarwacik committed Jan 23, 2024
1 parent 68dbecb commit 89f3183
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,35 @@ var cmdVersion = &cobra.Command{
},
}

var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
Long: "To load completions",
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
cmdRoot.GenBashCompletionV2(os.Stdout, true)
case "zsh":
cmdRoot.GenZshCompletion(os.Stdout)
case "fish":
cmdRoot.GenFishCompletion(os.Stdout, true)
case "powershell":
cmdRoot.GenPowerShellCompletionWithDesc(os.Stdout)
}
},
}

func init() {
// configure cobra help texts
setupHelp(cmdRoot)
fuzz.AddCommand(cmdRoot)
show.AddCommand(cmdRoot)
list.AddCommand(cmdRoot)
cmdRoot.AddCommand(cmdVersion)
cmdRoot.AddCommand(completionCmd)
}

func injectDefaultCommand(args []string) []string {
Expand Down

0 comments on commit 89f3183

Please sign in to comment.