prepareCustomAnnotationsForFlags setup annotations for go completions for registered flags
(cmd *Command)
| 534 | |
| 535 | // prepareCustomAnnotationsForFlags setup annotations for go completions for registered flags |
| 536 | func 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 | |
| 551 | func writeFlags(buf io.StringWriter, cmd *Command) { |
| 552 | prepareCustomAnnotationsForFlags(cmd) |
no test coverage detected