mirror of
https://github.com/spf13/cobra
synced 2025-05-05 12:57:22 +00:00
set to root command
This commit is contained in:
parent
4ee33b3c5b
commit
16f2a0735a
1 changed files with 5 additions and 4 deletions
|
@ -93,13 +93,14 @@ func (c *Command) RegisterFlagCompletionFunc(flagName string, f func(cmd *Comman
|
|||
return fmt.Errorf("RegisterFlagCompletionFunc: flag '%s' does not exist", flagName)
|
||||
}
|
||||
|
||||
if _, exists := c.Root().flagCompletionFunctions[flag]; exists {
|
||||
root := c.Root()
|
||||
if _, exists := root.flagCompletionFunctions[flag]; exists {
|
||||
return fmt.Errorf("RegisterFlagCompletionFunc: flag '%s' already registered", flagName)
|
||||
}
|
||||
if c.Root().flagCompletionFunctions == nil {
|
||||
c.Root().flagCompletionFunctions = map[*pflag.Flag]func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective){}
|
||||
if root.flagCompletionFunctions == nil {
|
||||
root.flagCompletionFunctions = map[*pflag.Flag]func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective){}
|
||||
}
|
||||
c.Root().flagCompletionFunctions[flag] = f
|
||||
root.flagCompletionFunctions[flag] = f
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue