Skip to content

Commit 1857580

Browse files
committed
Copy docs from go flag package about PrintDefaults
This commit copies the docs from the golang flag package to better explain the behavior of backticks in a flag's usage. Fixes spf13#200
1 parent c9bf08e commit 1857580

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

flag.go

+24-3
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,9 @@ func Set(name, value string) error {
475475
return CommandLine.Set(name, value)
476476
}
477477

478-
// PrintDefaults prints, to standard error unless configured
479-
// otherwise, the default values of all defined flags in the set.
478+
// PrintDefaults prints to standard error unless configured otherwise, the
479+
// default values of all defined command-line flags in the set. See the
480+
// documentation for the global function PrintDefaults for more information.
480481
func (f *FlagSet) PrintDefaults() {
481482
usages := f.FlagUsages()
482483
fmt.Fprint(f.Output(), usages)
@@ -718,7 +719,27 @@ func (f *FlagSet) FlagUsages() string {
718719
return f.FlagUsagesWrapped(0)
719720
}
720721

721-
// PrintDefaults prints to standard error the default values of all defined command-line flags.
722+
// PrintDefaults prints, to standard error unless configured otherwise,
723+
// a usage message showing the default settings of all defined
724+
// command-line flags.
725+
// For an integer valued flag x, the default output has the form
726+
// -x int
727+
// usage-message-for-x (default 7)
728+
// The usage message will appear on a separate line for anything but
729+
// a bool flag with a one-byte name. For bool flags, the type is
730+
// omitted and if the flag name is one byte the usage message appears
731+
// on the same line. The parenthetical default is omitted if the
732+
// default is the zero value for the type. The listed type, here int,
733+
// can be changed by placing a back-quoted name in the flag's usage
734+
// string; the first such item in the message is taken to be a parameter
735+
// name to show in the message and the back quotes are stripped from
736+
// the message when displayed. For instance, given
737+
// flag.String("I", "", "search `directory` for include files")
738+
// the output will be
739+
// -I directory
740+
// search directory for include files.
741+
//
742+
// To change the destination for flag messages, call CommandLine.SetOutput.
722743
func PrintDefaults() {
723744
CommandLine.PrintDefaults()
724745
}

0 commit comments

Comments
 (0)