1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-02 03:28:25 +08:00

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

This commit is contained in:
Matt Bell
2014-11-19 00:26:02 -08:00
parent bbf3a1f4d4
commit aa84f69231
2 changed files with 8 additions and 2 deletions

View File

@ -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 {

View File

@ -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