diff options
| author | Eric Paris <[email protected]> | 2015-04-07 20:39:13 -0400 |
|---|---|---|
| committer | Eric Paris <[email protected]> | 2015-04-07 20:39:13 -0400 |
| commit | db78b3f83a8d9270e6bdab11e0b94c26963ab3d2 (patch) | |
| tree | d6c148f230978c526ddf1845952ae224befd94b4 | |
| parent | 18d831e92d67eafd1b0db8af9ffddbd04f7ae1f4 (diff) | |
Declare Flag{ by name instead of order
In order to be able to add new (unitialized) fields to Flags{} declare
fields by name instead of order
| -rw-r--r-- | flag.go | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -141,12 +141,12 @@ type FlagSet struct { // A Flag represents the state of a flag. type Flag struct { - Name string // name as it appears on command line - Shorthand string // one-letter abbreviated flag - Usage string // help message - Value Value // value as set - DefValue string // default value (as text); for usage message - Changed bool // If the user set the value (or if left to default) + Name string // name as it appears on command line + Shorthand string // one-letter abbreviated flag + Usage string // help message + Value Value // value as set + DefValue string // default value (as text); for usage message + Changed bool // If the user set the value (or if left to default) Annotations map[string][]string // used by cobra.Command bash autocomple code } @@ -359,7 +359,13 @@ func (f *FlagSet) Var(value Value, name string, usage string) { // Like Var, but accepts a shorthand letter that can be used after a single dash. func (f *FlagSet) VarP(value Value, name, shorthand, usage string) { // Remember the default value as a string; it won't change. - flag := &Flag{name, shorthand, usage, value, value.String(), false, make(map[string][]string)} + flag := &Flag{ + Name: name, + Shorthand: shorthand, + Usage: usage, + Value: value, + DefValue: value.String(), + } f.AddFlag(flag) } @@ -554,7 +560,7 @@ func (f *FlagSet) parseArgs(args []string) (err error) { args, err = f.parseShortArg(s, args) } if err != nil { - return + return } } return |
