summaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2019-05-02 09:28:17 -0700
committerAlex Flint <[email protected]>2019-05-02 09:28:17 -0700
commit87be2d97907952e87203bd3a4b09cfbe49ce028d (patch)
tree7249020e562813f5a77467474f6f09d2c6375e82 /parse.go
parent5b649de04338e2ce398b9b1de3dc5f16144bdcd4 (diff)
add unittests for canParse
Diffstat (limited to 'parse.go')
-rw-r--r--parse.go55
1 files changed, 0 insertions, 55 deletions
diff --git a/parse.go b/parse.go
index 2a3442a..0633bb6 100644
--- a/parse.go
+++ b/parse.go
@@ -1,7 +1,6 @@
package arg
import (
- "encoding"
"encoding/csv"
"errors"
"fmt"
@@ -659,60 +658,6 @@ func setSlice(dest reflect.Value, values []string, trunc bool) error {
return nil
}
-// canParse returns true if the type can be parsed from a string
-func canParse(t reflect.Type) (parseable, boolean, multiple bool) {
- parseable = scalar.CanParse(t)
- boolean = isBoolean(t)
- if parseable {
- return
- }
-
- // Look inside pointer types
- if t.Kind() == reflect.Ptr {
- t = t.Elem()
- }
- // Look inside slice types
- if t.Kind() == reflect.Slice {
- multiple = true
- t = t.Elem()
- }
-
- parseable = scalar.CanParse(t)
- boolean = isBoolean(t)
- if parseable {
- return
- }
-
- // Look inside pointer types (again, in case of []*Type)
- if t.Kind() == reflect.Ptr {
- t = t.Elem()
- }
-
- parseable = scalar.CanParse(t)
- boolean = isBoolean(t)
- if parseable {
- return
- }
-
- return false, false, false
-}
-
-var textUnmarshalerType = reflect.TypeOf([]encoding.TextUnmarshaler{}).Elem()
-
-// isBoolean returns true if the type can be parsed from a single string
-func isBoolean(t reflect.Type) bool {
- switch {
- case t.Implements(textUnmarshalerType):
- return false
- case t.Kind() == reflect.Bool:
- return true
- case t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Bool:
- return true
- default:
- return false
- }
-}
-
// findOption finds an option from its name, or returns null if no spec is found
func findOption(specs []*spec, name string) *spec {
for _, spec := range specs {