X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/0f42105b1b59d1b5da764f34e6eb6a1137d7e1cb..8d47832e4637a40710838b9f4dc3353b58a28c93:/lib/cmd/parseflags.go diff --git a/lib/cmd/parseflags.go b/lib/cmd/parseflags.go index 3e872fcd11..707cacbf52 100644 --- a/lib/cmd/parseflags.go +++ b/lib/cmd/parseflags.go @@ -8,8 +8,13 @@ import ( "flag" "fmt" "io" + "reflect" ) +// Hack to enable checking whether a given FlagSet's Usage method is +// the (private) default one. +var defaultFlagSet = flag.NewFlagSet("none", flag.ContinueOnError) + // ParseFlags calls f.Parse(args) and prints appropriate error/help // messages to stderr. // @@ -34,7 +39,12 @@ func ParseFlags(f FlagSet, prog string, args []string, positional string, stderr } return true, 0 case flag.ErrHelp: - if f, ok := f.(*flag.FlagSet); ok && f.Usage != nil { + // Use our own default usage func, not the one + // provided by the flag pkg, if the caller hasn't set + // one. (We use reflect to determine whether f.Usage + // is the private defaultUsage func that + // flag.NewFlagSet uses.) + if f, ok := f.(*flag.FlagSet); ok && f.Usage != nil && reflect.ValueOf(f.Usage).String() != reflect.ValueOf(defaultFlagSet.Usage).String() { f.SetOutput(stderr) f.Usage() } else {