|
case reflect.String: |
|
p := f.Addr().Interface().(*string) |
|
flags.string(p, flagName, shorthand, f.String(), flagHelp(ft)) |
|
case reflect.Bool: |
|
p := f.Addr().Interface().(*bool) |
|
flags.bool(p, flagName, shorthand, f.Bool(), flagHelp(ft)) |
|
case reflect.Int: |
|
p := f.Addr().Interface().(*int) |
|
val := int(f.Int()) |
|
flags.int(p, flagName, shorthand, val, flagHelp(ft)) |
|
case reflect.Int64: |
|
p := f.Addr().Interface().(*int64) |
|
flags.int64(p, flagName, shorthand, f.Int(), flagHelp(ft)) |
|
case reflect.Float64: |
|
p := f.Addr().Interface().(*float64) |
|
flags.float64(p, flagName, shorthand, f.Float(), flagHelp(ft)) |
|
case reflect.Uint: |
|
p := f.Addr().Interface().(*uint) |
|
val := uint(f.Uint()) |
|
flags.uint(p, flagName, shorthand, val, flagHelp(ft)) |
|
case reflect.Uint64: |
|
p := f.Addr().Interface().(*uint64) |
|
flags.uint64(p, flagName, shorthand, f.Uint(), flagHelp(ft)) |
|
case reflect.Slice: |
|
if !flags.pflag { |
|
return fmt.Errorf("cannot support slice field at '%v' with stdlib flag pkg.", flagName) |
|
} |
|
switch ft.Type.Elem().Kind() { |
|
case reflect.String: |
|
p := f.Addr().Interface().(*[]string) |
|
flags.stringSlice(p, flagName, shorthand, *p, flagHelp(ft)) |
|
case reflect.Bool: |
|
p := f.Addr().Interface().(*[]bool) |
|
flags.boolSlice(p, flagName, shorthand, *p, flagHelp(ft)) |
|
case reflect.Int: |
|
p := f.Addr().Interface().(*[]int) |
|
flags.intSlice(p, flagName, shorthand, *p, flagHelp(ft)) |
|
case reflect.Uint: |
|
p := f.Addr().Interface().(*[]uint) |
|
flags.uintSlice(p, flagName, shorthand, *p, flagHelp(ft)) |
|
default: |
|
return fmt.Errorf("encountered unsupported slice type/kind: %#v at %s", f, prefix) |
|
} |
|
case reflect.Float32: |
|
if !flags.pflag { |
|
return fmt.Errorf("cannot support float32 field at '%v' with stdlib flag pkg.", flagName) |
|
} |
|
p := f.Addr().Interface().(*float32) |
|
flags.float32(p, flagName, shorthand, *p, flagHelp(ft)) |
|
case reflect.Int16: |
|
if !flags.pflag { |
|
return fmt.Errorf("cannot support int16 field at '%v' with stdlib flag pkg.", flagName) |
|
} |
|
p := f.Addr().Interface().(*int16) |
|
flags.int16(p, flagName, shorthand, *p, flagHelp(ft)) |
|
case reflect.Int32: |
|
if !flags.pflag { |
|
return fmt.Errorf("cannot support int32 field at '%v' with stdlib flag pkg.", flagName) |
|
} |
|
p := f.Addr().Interface().(*int32) |
|
flags.int32(p, flagName, shorthand, *p, flagHelp(ft)) |
|
case reflect.Uint16: |
|
if !flags.pflag { |
|
return fmt.Errorf("cannot support uint16 field at '%v' with stdlib flag pkg.", flagName) |
|
} |
|
p := f.Addr().Interface().(*uint16) |
|
flags.uint16(p, flagName, shorthand, *p, flagHelp(ft)) |
|
case reflect.Uint32: |
|
if !flags.pflag { |
|
return fmt.Errorf("cannot support uint32 field at '%v' with stdlib flag pkg.", flagName) |
|
} |
|
p := f.Addr().Interface().(*uint32) |
|
flags.uint32(p, flagName, shorthand, *p, flagHelp(ft)) |
|
case reflect.Uint8: |
|
if !flags.pflag { |
|
return fmt.Errorf("cannot support uint8 field at '%v' with stdlib flag pkg.", flagName) |
|
} |
|
p := f.Addr().Interface().(*uint8) |
|
flags.uint8(p, flagName, shorthand, *p, flagHelp(ft)) |
|
case reflect.Int8: |
|
if !flags.pflag { |
|
return fmt.Errorf("cannot support int8 field at '%v' with stdlib flag pkg.", flagName) |
|
} |
|
p := f.Addr().Interface().(*int8) |
|
flags.int8(p, flagName, shorthand, *p, flagHelp(ft)) |
While attempting to use a wrapped version of
time.Duration, I ran into a crash when using commandeer.commandeer/com.go
Lines 274 to 358 in 07c6265
All of these type assertions will panic if the type is named.