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

Function genFlagResult

doc/yaml_docs.go:149–175  ·  view source on GitHub ↗
(flags *pflag.FlagSet)

Source from the content-addressed store, hash-verified

147}
148
149func genFlagResult(flags *pflag.FlagSet) []cmdOption {
150 var result []cmdOption
151
152 flags.VisitAll(func(flag *pflag.Flag) {
153 // Todo, when we mark a shorthand is deprecated, but specify an empty message.
154 // The flag.ShorthandDeprecated is empty as the shorthand is deprecated.
155 // Using len(flag.ShorthandDeprecated) > 0 can't handle this, others are ok.
156 if len(flag.ShorthandDeprecated) == 0 && len(flag.Shorthand) > 0 {
157 opt := cmdOption{
158 flag.Name,
159 flag.Shorthand,
160 flag.DefValue,
161 forceMultiLine(flag.Usage),
162 }
163 result = append(result, opt)
164 } else {
165 opt := cmdOption{
166 Name: flag.Name,
167 DefaultValue: forceMultiLine(flag.DefValue),
168 Usage: forceMultiLine(flag.Usage),
169 }
170 result = append(result, opt)
171 }
172 })
173
174 return result
175}

Callers 1

GenYamlCustomFunction · 0.85

Calls 1

forceMultiLineFunction · 0.85

Tested by

no test coverage detected