SetAnnotation allows one to set arbitrary annotations on a flag in the FlagSet. This is sometimes used by spf13/cobra programs which want to generate additional bash completion information.
(name, key string, values []string)
| 519 | // This is sometimes used by spf13/cobra programs which want to generate additional |
| 520 | // bash completion information. |
| 521 | func (f *FlagSet) SetAnnotation(name, key string, values []string) error { |
| 522 | normalName := f.normalizeFlagName(name) |
| 523 | flag, ok := f.formal[normalName] |
| 524 | if !ok { |
| 525 | return &NotExistError{name: name, messageType: flagNoSuchFlagMessage} |
| 526 | } |
| 527 | if flag.Annotations == nil { |
| 528 | flag.Annotations = map[string][]string{} |
| 529 | } |
| 530 | flag.Annotations[key] = values |
| 531 | return nil |
| 532 | } |
| 533 | |
| 534 | // Changed returns true if the flag was explicitly set during Parse() and false |
| 535 | // otherwise |