Skip to content

Commit 20f077e

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 ccc1fa0 commit 20f077e

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
@@ -469,8 +469,9 @@ func Set(name, value string) error {
469469
return CommandLine.Set(name, value)
470470
}
471471

472-
// PrintDefaults prints, to standard error unless configured
473-
// otherwise, the default values of all defined flags in the set.
472+
// PrintDefaults prints to standard error unless configured otherwise, the
473+
// default values of all defined command-line flags in the set. See the
474+
// documentation for the global function PrintDefaults for more information.
474475
func (f *FlagSet) PrintDefaults() {
475476
usages := f.FlagUsages()
476477
fmt.Fprint(f.Output(), usages)
@@ -712,7 +713,27 @@ func (f *FlagSet) FlagUsages() string {
712713
return f.FlagUsagesWrapped(0)
713714
}
714715

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

0 commit comments

Comments
 (0)