mirror of https://github.com/golang/go.git
flag: document the zero value of FlagSet
R=golang-dev, r CC=golang-dev https://golang.org/cl/12403043
This commit is contained in:
parent
034d5fcc30
commit
321ede78e3
|
|
@ -256,7 +256,8 @@ const (
|
|||
PanicOnError
|
||||
)
|
||||
|
||||
// A FlagSet represents a set of defined flags.
|
||||
// A FlagSet represents a set of defined flags. The zero value of a FlagSet
|
||||
// has no name and has ContinueOnError error handling.
|
||||
type FlagSet struct {
|
||||
// Usage is the function called when an error occurs while parsing flags.
|
||||
// The field is a function (not a method) that may be changed to point to
|
||||
|
|
@ -391,7 +392,11 @@ func PrintDefaults() {
|
|||
|
||||
// defaultUsage is the default function to print a usage message.
|
||||
func defaultUsage(f *FlagSet) {
|
||||
fmt.Fprintf(f.out(), "Usage of %s:\n", f.name)
|
||||
if f.name == "" {
|
||||
fmt.Fprintf(f.out(), "Usage:\n")
|
||||
} else {
|
||||
fmt.Fprintf(f.out(), "Usage of %s:\n", f.name)
|
||||
}
|
||||
f.PrintDefaults()
|
||||
}
|
||||
|
||||
|
|
@ -658,7 +663,12 @@ func (f *FlagSet) Var(value Value, name string, usage string) {
|
|||
flag := &Flag{name, usage, value, value.String()}
|
||||
_, alreadythere := f.formal[name]
|
||||
if alreadythere {
|
||||
msg := fmt.Sprintf("%s flag redefined: %s", f.name, name)
|
||||
var msg string
|
||||
if f.name == "" {
|
||||
msg = fmt.Sprintf("flag redefined: %s", name)
|
||||
} else {
|
||||
msg = fmt.Sprintf("%s flag redefined: %s", f.name, name)
|
||||
}
|
||||
fmt.Fprintln(f.out(), msg)
|
||||
panic(msg) // Happens only if flags are declared with identical names
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue