From 6e29cd8c7d2a68b257f0a3600a77e1539c6f6c04 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Sat, 15 Aug 2015 15:17:20 -0400 Subject: Reduce code duplication in PrintDefaults/FlagUsages They both did the same thing. So use one in the other. --- flag.go | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/flag.go b/flag.go index 0dce0a3..6695472 100644 --- a/flag.go +++ b/flag.go @@ -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 { -- cgit v1.2.3