Skip to content

Commit

Permalink
Update defaultUsage
Browse files Browse the repository at this point in the history
This commit updates defaultUsage to match the current state in golang's flag.go.

Fixes spf13#242
  • Loading branch information
cornfeedhobo committed Mar 10, 2021
1 parent 64b2044 commit 73467ef
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,17 @@ func PrintDefaults() {
}

// defaultUsage is the default function to print a usage message.
func defaultUsage(f *FlagSet) {
func (f *FlagSet) defaultUsage() {
if f.name == "" {
fmt.Fprintf(f.Output(), "Usage:\n")
} else {
fmt.Fprintf(f.Output(), "Usage of %s:\n", f.name)
}
fmt.Fprintf(f.Output(), "Usage of %s:\n", f.name)
f.PrintDefaults()
}

// NOTE: Usage is not just defaultUsage(CommandLine)
// NOTE: Usage is not just CommandLine.defaultUsage()
// because it serves (via godoc flag Usage) as the example
// for how to write your own usage function.

Expand All @@ -680,7 +685,7 @@ func defaultUsage(f *FlagSet) {
// By default it prints a simple header and calls PrintDefaults; for details about the
// format of the output and how to control it, see the documentation for PrintDefaults.
var Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
fmt.Fprintf(CommandLine.Output(), "Usage of %s:\n", os.Args[0])
PrintDefaults()
}

Expand Down Expand Up @@ -828,7 +833,7 @@ func (f *FlagSet) usage() {
if f == CommandLine {
Usage()
} else if f.Usage == nil {
defaultUsage(f)
f.defaultUsage()
} else {
f.Usage()
}
Expand Down

0 comments on commit 73467ef

Please sign in to comment.