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

Function manPrintFlags

doc/man_docs.go:159–185  ·  view source on GitHub ↗
(buf io.StringWriter, flags *pflag.FlagSet)

Source from the content-addressed store, hash-verified

157}
158
159func manPrintFlags(buf io.StringWriter, flags *pflag.FlagSet) {
160 flags.VisitAll(func(flag *pflag.Flag) {
161 if len(flag.Deprecated) > 0 || flag.Hidden {
162 return
163 }
164 format := ""
165 if len(flag.Shorthand) > 0 && len(flag.ShorthandDeprecated) == 0 {
166 format = fmt.Sprintf("**-%s**, **--%s**", flag.Shorthand, flag.Name)
167 } else {
168 format = fmt.Sprintf("**--%s**", flag.Name)
169 }
170 if len(flag.NoOptDefVal) > 0 {
171 format += "["
172 }
173 if flag.Value.Type() == "string" {
174 // put quotes on the value
175 format += "=%q"
176 } else {
177 format += "=%s"
178 }
179 if len(flag.NoOptDefVal) > 0 {
180 format += "]"
181 }
182 format += "\n\t%s\n\n"
183 cobra.WriteStringAndCheck(buf, fmt.Sprintf(format, flag.DefValue, flag.Usage))
184 })
185}
186
187func manPrintOptions(buf io.StringWriter, command *cobra.Command) {
188 flags := command.NonInheritedFlags()

Callers 2

manPrintOptionsFunction · 0.85

Calls 2

WriteStringAndCheckFunction · 0.92
TypeMethod · 0.80

Tested by 1