Skip to content

Commit 3e1db0e

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 e9be5fa commit 3e1db0e

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
@@ -472,8 +472,9 @@ func Set(name, value string) error {
472472
return CommandLine.Set(name, value)
473473
}
474474

475-
// PrintDefaults prints, to standard error unless configured
476-
// otherwise, the default values of all defined flags in the set.
475+
// PrintDefaults prints to standard error unless configured otherwise, the
476+
// default values of all defined command-line flags in the set. See the
477+
// documentation for the global function PrintDefaults for more information.
477478
func (f *FlagSet) PrintDefaults() {
478479
usages := f.FlagUsages()
479480
fmt.Fprint(f.Output(), usages)
@@ -715,7 +716,27 @@ func (f *FlagSet) FlagUsages() string {
715716
return f.FlagUsagesWrapped(0)
716717
}
717718

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

0 commit comments

Comments
 (0)