Skip to content

Commit

Permalink
Allow overriding Run/RunE of comp cmds
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
  • Loading branch information
marckhouzam committed Nov 3, 2021
1 parent 21dac9b commit d7f7e17
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions completionCmd.go
Expand Up @@ -111,8 +111,10 @@ $ %[1]s %[2]s bash > /usr/local/etc/bash_completion.d/%[1]s
You will need to start a new shell for this setup to take effect.`, c.Root().Name(), CompletionCmd.Name())
}
bash.RunE = func(cmd *Command, args []string) error {
return cmd.Root().GenBashCompletionV2(out, !noDesc)
if bash.RunE == nil && bash.Run == nil {
bash.RunE = func(cmd *Command, args []string) error {
return cmd.Root().GenBashCompletionV2(out, !noDesc)
}
}

bash.ResetFlags() // Tests can call this function multiple times in a row, so we must reset
Expand All @@ -138,11 +140,13 @@ $ %[1]s %[2]s zsh > /usr/local/share/zsh/site-functions/_%[1]s
You will need to start a new shell for this setup to take effect.`, c.Root().Name(), CompletionCmd.Name())
}
zsh.RunE = func(cmd *Command, args []string) error {
if noDesc {
return cmd.Root().GenZshCompletionNoDesc(out)
if zsh.RunE == nil && zsh.Run == nil {
zsh.RunE = func(cmd *Command, args []string) error {
if noDesc {
return cmd.Root().GenZshCompletionNoDesc(out)
}
return cmd.Root().GenZshCompletion(out)
}
return cmd.Root().GenZshCompletion(out)
}

zsh.ResetFlags() // Tests can call this function multiple times in a row, so we must reset
Expand All @@ -163,8 +167,10 @@ $ %[1]s %[2]s fish > ~/.config/fish/completions/%[1]s.fish
You will need to start a new shell for this setup to take effect.`, c.Root().Name(), CompletionCmd.Name())
}
fish.RunE = func(cmd *Command, args []string) error {
return cmd.Root().GenFishCompletion(out, !noDesc)
if fish.RunE == nil && fish.Run == nil {
fish.RunE = func(cmd *Command, args []string) error {
return cmd.Root().GenFishCompletion(out, !noDesc)
}
}

fish.ResetFlags() // Tests can call this function multiple times in a row, so we must reset
Expand All @@ -183,11 +189,13 @@ PS C:\> %[1]s %[2]s powershell | Out-String | Invoke-Expression
To load completions for every new session, add the output of the above command
to your powershell profile.`, c.Root().Name(), CompletionCmd.Name())
}
pwsh.RunE = func(cmd *Command, args []string) error {
if noDesc {
return cmd.Root().GenPowerShellCompletion(out)
if pwsh.RunE == nil && pwsh.Run == nil {
pwsh.RunE = func(cmd *Command, args []string) error {
if noDesc {
return cmd.Root().GenPowerShellCompletion(out)
}
return cmd.Root().GenPowerShellCompletionWithDesc(out)
}
return cmd.Root().GenPowerShellCompletionWithDesc(out)
}

pwsh.ResetFlags() // Tests can call this function multiple times in a row, so we must reset
Expand Down

0 comments on commit d7f7e17

Please sign in to comment.