mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-03 13:00:37 +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 {
|
type OptionValue struct {
|
||||||
value interface{}
|
value interface{}
|
||||||
found bool
|
found bool
|
||||||
|
def Option
|
||||||
}
|
}
|
||||||
|
|
||||||
// Found returns true if the option value was provided by the user (not a default value)
|
// 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
|
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
|
// value accessor methods, gets the value as a certain type
|
||||||
func (ov OptionValue) Bool() (value bool, found bool, err error) {
|
func (ov OptionValue) Bool() (value bool, found bool, err error) {
|
||||||
if !ov.found {
|
if !ov.found {
|
||||||
|
@ -102,12 +102,12 @@ func (r *request) Option(name string) *OptionValue {
|
|||||||
for _, n := range option.Names() {
|
for _, n := range option.Names() {
|
||||||
val, found := r.options[n]
|
val, found := r.options[n]
|
||||||
if found {
|
if found {
|
||||||
return &OptionValue{val, found}
|
return &OptionValue{val, found, option}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MAYBE_TODO: use default value instead of nil
|
// 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
|
// Options returns a copy of the option map
|
||||||
|
Reference in New Issue
Block a user