Skip to content

Commit

Permalink
fixed completion commands (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
zackbradys authored Aug 29, 2024
1 parent 16fa03f commit 02231d7
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions cmd/hauler/cli/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func addCompletion(parent *cobra.Command) {
cmd := &cobra.Command{
Use: "hauler completion",
Use: "completion",
Short: "Generates completion scripts for various shells",
Long: `The completion sub-command generates completion scripts for various shells.`,
}
Expand All @@ -24,11 +24,6 @@ func addCompletion(parent *cobra.Command) {
parent.AddCommand(cmd)
}

func completionError(err error) ([]string, cobra.ShellCompDirective) {
cobra.CompError(err.Error())
return nil, cobra.ShellCompDirectiveError
}

func addCompletionZsh() *cobra.Command {
cmd := &cobra.Command{
Use: "zsh",
Expand All @@ -51,7 +46,7 @@ func addCompletionZsh() *cobra.Command {
mv _hauler ~/.oh-my-zsh/completions # oh-my-zsh
mv _hauler ~/.zprezto/modules/completion/external/src/ # zprezto`,
Run: func(cmd *cobra.Command, args []string) {
cmd.GenZshCompletion(os.Stdout)
cmd.Root().GenZshCompletion(os.Stdout)
// Cobra doesn't source zsh completion file, explicitly doing it here
fmt.Println("compdef _hauler hauler")
},
Expand All @@ -73,7 +68,7 @@ func addCompletionBash() *cobra.Command {
# ~/.bashrc or ~/.profile
command -v hauler >/dev/null && . <(hauler completion bash)`,
Run: func(cmd *cobra.Command, args []string) {
cmd.GenBashCompletion(os.Stdout)
cmd.Root().GenBashCompletion(os.Stdout)
},
}
return cmd
Expand All @@ -90,7 +85,7 @@ func addCompletionFish() *cobra.Command {
See http://fishshell.com/docs/current/index.html#completion-own for more details`,
Run: func(cmd *cobra.Command, args []string) {
cmd.GenFishCompletion(os.Stdout, true)
cmd.Root().GenFishCompletion(os.Stdout, true)
},
}
return cmd
Expand All @@ -117,7 +112,7 @@ func addCompletionPowershell() *cobra.Command {
cd "${XDG_CONFIG_HOME:-"$HOME/.config/"}/powershell/modules"
hauler completion powershell >> hauler-completions.ps1`,
Run: func(cmd *cobra.Command, args []string) {
cmd.GenPowerShellCompletion(os.Stdout)
cmd.Root().GenPowerShellCompletion(os.Stdout)
},
}
return cmd
Expand Down

0 comments on commit 02231d7

Please sign in to comment.