MCPcopy
hub / github.com/spf13/cobra / prepareCustomAnnotationsForFlags

Function prepareCustomAnnotationsForFlags

bash_completions.go:536–549  ·  view source on GitHub ↗

prepareCustomAnnotationsForFlags setup annotations for go completions for registered flags

(cmd *Command)

Source from the content-addressed store, hash-verified

534
535// prepareCustomAnnotationsForFlags setup annotations for go completions for registered flags
536func prepareCustomAnnotationsForFlags(cmd *Command) {
537 flagCompletionMutex.RLock()
538 defer flagCompletionMutex.RUnlock()
539 for flag := range flagCompletionFunctions {
540 // Make sure the completion script calls the __*_go_custom_completion function for
541 // every registered flag. We need to do this here (and not when the flag was registered
542 // for completion) so that we can know the root command name for the prefix
543 // of __<prefix>_go_custom_completion
544 if flag.Annotations == nil {
545 flag.Annotations = map[string][]string{}
546 }
547 flag.Annotations[BashCompCustom] = []string{fmt.Sprintf("__%[1]s_handle_go_custom_completion", cmd.Root().Name())}
548 }
549}
550
551func writeFlags(buf io.StringWriter, cmd *Command) {
552 prepareCustomAnnotationsForFlags(cmd)

Callers 1

writeFlagsFunction · 0.85

Calls 2

NameMethod · 0.80
RootMethod · 0.80

Tested by

no test coverage detected