aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspf13 <[email protected]>2013-11-12 09:36:01 -0500
committerspf13 <[email protected]>2013-11-12 09:36:01 -0500
commit94e98a55fb412fcbcfc302555cb990f5e1590627 (patch)
tree7342d902f61066da83e79a5c55ef9e9bd2d30fa8
parent5bc978f8eed31e419a5589266ca98a88812147d9 (diff)
adding changed flag on flag to track user set vs default
-rw-r--r--flag.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/flag.go b/flag.go
index bce00d1..b741e7b 100644
--- a/flag.go
+++ b/flag.go
@@ -282,6 +282,7 @@ type Flag struct {
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)
}
// sortFlags returns the flags as a slice in lexicographical sorted order.
@@ -370,6 +371,7 @@ func (f *FlagSet) Set(name, value string) error {
f.actual = make(map[string]*Flag)
}
f.actual[name] = flag
+ f.Lookup(name).Changed = true
return nil
}
@@ -868,7 +870,7 @@ 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()}
+ flag := &Flag{name, shorthand, usage, value, value.String(), false}
f.AddFlag(flag)
}
@@ -948,7 +950,7 @@ func (f *FlagSet) setFlag(flag *Flag, value string, origArg string) error {
f.actual = make(map[string]*Flag)
}
f.actual[flag.Name] = flag
-
+ flag.Changed = true
return nil
}