Skip to content
Myr

feat: add getters for flag completions (#1943)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Alexandru-Claudius Virtopeanu · committed by GitHub · parent 0c72800 · Browse files · 1 file+19 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+19 added−0 removed

  • other:+19 added−0 removed

1 file+19 added−0 removed

modified:completions.go+19 added
143 unmodified lines
144 flagCompletionFunctions[flag] = f145 return nil146}147148// GetFlagCompletion returns the completion function for the given flag, if available.149func GetFlagCompletion(flag *pflag.Flag) (func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective), bool) {150 flagCompletionMutex.RLock()151 defer flagCompletionMutex.RUnlock()152153 completionFunc, exists := flagCompletionFunctions[flag]154 return completionFunc, exists155}156157// GetFlagCompletionByName returns the completion function for the given flag in the command by name, if available.158func (c *Command) GetFlagCompletionByName(flagName string) (func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective), bool) {159 flag := c.Flags().Lookup(flagName)160 if flag == nil {161 return nil, false162 }163164 return GetFlagCompletion(flag)165}166167// Returns a string listing the different directive enabled in the specified parameter168func (d ShellCompDirective) string() string {169 var directives []string170 if d&ShellCompDirectiveError != 0 {
727 unmodified lines