Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5b42bf560b
Fetching contributors…

Cannot retrieve contributors at this time

78 lines (57 sloc) 1.291 kb
package flags
import (
"reflect"
)
func (option *Option) canArgument() bool {
if option.isBool() {
return false
}
if option.isFunc() {
return (option.Value.Type().NumIn() > 0)
}
return true
}
func (option *Option) isBool() bool {
tp := option.Value.Type()
switch tp.Kind() {
case reflect.Bool:
return true
case reflect.Slice:
return (tp.Elem().Kind() == reflect.Bool)
}
return false
}
func (option *Option) isFunc() bool {
return option.Value.Type().Kind() == reflect.Func
}
func (option *Option) iniName() string {
if len(option.iniUsedName) != 0 {
return option.iniUsedName
}
name := option.Field.Tag.Get("ini-name")
if len(name) != 0 {
return name
}
return option.Field.Name
}
func (option *Option) call(value *string) error {
var retval []reflect.Value
if value == nil {
retval = option.Value.Call(nil)
} else {
tp := option.Value.Type().In(0)
val := reflect.New(tp)
val = reflect.Indirect(val)
if err := convert(*value, val, option.Field.Tag); err != nil {
return err
}
retval = option.Value.Call([]reflect.Value{val})
}
if len(retval) == 1 && retval[0].Type() == reflect.TypeOf((*error)(nil)).Elem() {
if retval[0].Interface() == nil {
return nil
}
return retval[0].Interface().(error)
}
return nil
}
Jump to Line
Something went wrong with that request. Please try again.