commands: Added a 'Definition()' method to OptionValue to get a reference to the option definiton
Matt Bell committed
Nov 19, 2014 at 00:26 UTC
aa84f69231e9e62fea34499c1215bd3590a11071
2 files changed
+8
-2
commands/option.go
+6
@@ -83,6 +83,7 @@ func StringOption(names ...string) Option {
83
type OptionValue struct {
84
value interface{}
85
found bool
86
+ def Option
87
}
88
89
// Found returns true if the option value was provided by the user (not a default value)
@@ -90,6 +91,11 @@ func (ov OptionValue) Found() bool {
91
return ov.found
92
}
93
94
+// Definition returns the option definition for the provided value
95
+func (ov OptionValue) Definition() Option {
96
+ return ov.def
97
+}
98
+
99
// value accessor methods, gets the value as a certain type
100
func (ov OptionValue) Bool() (value bool, found bool, err error) {
101
if !ov.found {
commands/request.go
+2
-2
@@ -102,12 +102,12 @@ func (r *request) Option(name string) *OptionValue {
102
for _, n := range option.Names() {
103
val, found := r.options[n]
104
if found {
105
- return &OptionValue{val, found}
105
+ return &OptionValue{val, found, option}
106
}
107
}
108
109
// MAYBE_TODO: use default value instead of nil
110
- return &OptionValue{nil, false}
110
+ return &OptionValue{nil, false, option}
111
}
112
113
// Options returns a copy of the option map