mirror of
https://github.com/spf13/cobra
synced 2025-05-05 12:57:22 +00:00
Allow overriding Run/RunE of comp cmds
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
This commit is contained in:
parent
3ae090bcba
commit
9fa0b83ed0
1 changed files with 20 additions and 12 deletions
|
@ -112,9 +112,11 @@ $ %[1]s %[2]s %[3]s > /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(), BashCompletionCmd.Name())
|
||||
}
|
||||
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
|
||||
if haveNoDescFlag {
|
||||
|
@ -140,12 +142,14 @@ $ %[1]s %[2]s %[3]s > /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(), ZshCompletionCmd.Name())
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
zsh.ResetFlags() // Tests can call this function multiple times in a row, so we must reset
|
||||
if haveNoDescFlag {
|
||||
|
@ -166,9 +170,11 @@ $ %[1]s %[2]s %[3]s > ~/.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(), FishCompletionCmd.Name())
|
||||
}
|
||||
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
|
||||
if haveNoDescFlag {
|
||||
|
@ -187,12 +193,14 @@ To load completions for every new session, add the output of the above command
|
|||
to your powershell profile.`,
|
||||
c.Root().Name(), CompletionCmd.Name(), PwshCompletionCmd.Name())
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
pwsh.ResetFlags() // Tests can call this function multiple times in a row, so we must reset
|
||||
if haveNoDescFlag {
|
||||
|
|
Loading…
Add table
Reference in a new issue