diff options
| author | Alex Flint <[email protected]> | 2017-02-15 18:37:19 -0800 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2017-02-15 18:37:19 -0800 |
| commit | 44a8b85d8250005629dd43d78b3e305bc57e1e24 (patch) | |
| tree | ab73e8fc3d578d10e172553c2a6ddcd886b9136f /parse.go | |
| parent | 38c51f4cabd18d77e57fc41ee52f9b3b47430cdb (diff) | |
deal with booleans correctly
Diffstat (limited to 'parse.go')
| -rw-r--r-- | parse.go | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -1,6 +1,7 @@ package arg import ( + "encoding" "errors" "fmt" "os" @@ -445,9 +446,21 @@ func canParse(t reflect.Type) (parseable, boolean, multiple bool) { return false, false, false } +var textUnmarshalerType = reflect.TypeOf([]encoding.TextUnmarshaler{}).Elem() + // isScalar returns true if the type can be parsed from a single string -func isScalar(t reflect.Type) (bool, bool) { - return scalar.CanParse(t), t.Kind() == reflect.Bool +func isScalar(t reflect.Type) (parseable, boolean bool) { + parseable = scalar.CanParse(t) + switch { + case t.Implements(textUnmarshalerType): + return parseable, false + case t.Kind() == reflect.Bool: + return parseable, true + case t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Bool: + return parseable, true + default: + return parseable, false + } } // set a value from a string |
