MCPcopy
hub / github.com/spf13/pflag / SetAnnotation

Method SetAnnotation

flag.go:521–532  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

519// This is sometimes used by spf13/cobra programs which want to generate additional
520// bash completion information.
521func (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

Callers 1

TestAnnotationFunction · 0.95

Calls 1

normalizeFlagNameMethod · 0.95

Tested by 1

TestAnnotationFunction · 0.76