mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 19:24:14 +08:00
commands: Added a 'Definition()' method to OptionValue to get a reference to the option definiton
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user