Commit aa84f692 authored by Matt Bell's avatar Matt Bell

commands: Added a 'Definition()' method to OptionValue to get a reference to the option definiton

parent bbf3a1f4
......@@ -83,6 +83,7 @@ func StringOption(names ...string) Option {
type OptionValue struct {
value interface{}
found bool
def Option
}
// 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 {
return ov.found
}
// Definition returns the option definition for the provided value
func (ov OptionValue) Definition() Option {
return ov.def
}
// value accessor methods, gets the value as a certain type
func (ov OptionValue) Bool() (value bool, found bool, err error) {
if !ov.found {
......
......@@ -102,12 +102,12 @@ func (r *request) Option(name string) *OptionValue {
for _, n := range option.Names() {
val, found := r.options[n]
if found {
return &OptionValue{val, found}
return &OptionValue{val, found, option}
}
}
// MAYBE_TODO: use default value instead of nil
return &OptionValue{nil, false}
return &OptionValue{nil, false, option}
}
// Options returns a copy of the option map
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment