diff options
| author | Eric Paris <[email protected]> | 2015-08-15 15:17:20 -0400 |
|---|---|---|
| committer | Eric Paris <[email protected]> | 2015-08-15 15:17:20 -0400 |
| commit | 6e29cd8c7d2a68b257f0a3600a77e1539c6f6c04 (patch) | |
| tree | 8605ab933802980f987322b4f26b2caa0ff71c74 /flag.go | |
| parent | 1ad164813157ed6d752ca39b5ac46eb3ae99093b (diff) | |
Reduce code duplication in PrintDefaults/FlagUsages
They both did the same thing. So use one in the other.
Diffstat (limited to 'flag.go')
| -rw-r--r-- | flag.go | 27 |
1 files changed, 2 insertions, 25 deletions
@@ -347,31 +347,8 @@ func Set(name, value string) error { // PrintDefaults prints, to standard error unless configured // otherwise, the default values of all defined flags in the set. func (f *FlagSet) PrintDefaults() { - f.VisitAll(func(flag *Flag) { - if len(flag.Deprecated) > 0 { - return - } - format := "" - // ex: w/ option string argument '-%s, --%s[=%q]: %s\n' - if len(flag.Shorthand) > 0 { - format = " -%s, --%s" - } else { - format = " %s --%s" - } - if len(flag.NoOptDefVal) > 0 { - format = format + "[" - } - if _, ok := flag.Value.(*stringValue); ok { - format = format + "=%q" - } else { - format = format + "=%s" - } - if len(flag.NoOptDefVal) > 0 { - format = format + "]" - } - format = format + ": %s\n" - fmt.Fprintf(f.out(), format, flag.Shorthand, flag.Name, flag.DefValue, flag.Usage) - }) + usages := f.FlagUsages() + fmt.Fprintf(f.out(), "%s", usages) } func (f *FlagSet) FlagUsages() string { |
