func manPrintFlags(out *bytes.Buffer, flags *pflag.FlagSet) { flags.VisitAll(func(flag *pflag.Flag) { if len(flag.Deprecated) > 0 || flag.Hidden { return } format := "" if len(flag.Shorthand) > 0 { format = "**-%s**, **--%s**" } else { format = "%s**--%s**" } if len(flag.NoOptDefVal) > 0 { format = format + "[" } if flag.Value.Type() == "string" { // put quotes on the value format = format + "=%q" } else { format = format + "=%s" } if len(flag.NoOptDefVal) > 0 { format = format + "]" } format = format + "\n\t%s\n\n" fmt.Fprintf(out, format, flag.Shorthand, flag.Name, flag.DefValue, flag.Usage) }) }
func etcdFlagUsages(flagSet *pflag.FlagSet) string { x := new(bytes.Buffer) flagSet.VisitAll(func(flag *pflag.Flag) { if len(flag.Deprecated) > 0 { return } format := "" if len(flag.Shorthand) > 0 { format = " -%s, --%s" } else { format = " %s --%s" } if len(flag.NoOptDefVal) > 0 { format = format + "[" } if flag.Value.Type() == "string" { // put quotes on the value format = format + "=%q" } else { format = format + "=%s" } if len(flag.NoOptDefVal) > 0 { format = format + "]" } format = format + "\t%s\n" shorthand := flag.Shorthand fmt.Fprintf(x, format, shorthand, flag.Name, flag.DefValue, flag.Usage) }) return x.String() }
// Test if the named flag is a boolean flag. func isBooleanShortFlag(name string, f *flag.FlagSet) bool { result := false f.VisitAll(func(f *flag.Flag) { if f.Shorthand == name && f.Value.Type() == "bool" { result = true } }) return result }