summaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2017-02-15 18:19:41 -0800
committerAlex Flint <[email protected]>2017-02-15 18:19:41 -0800
commit6859799559dab59729eb5fefeb53080db9b92545 (patch)
treedd8a6476af78f555f067c923c815b78844161248 /parse.go
parent765ccf745937c16486999600ecf789c646ac2e6c (diff)
use go-scalar, vendoring
Diffstat (limited to 'parse.go')
-rw-r--r--parse.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/parse.go b/parse.go
index a47f464..9e4e712 100644
--- a/parse.go
+++ b/parse.go
@@ -7,6 +7,8 @@ import (
"path/filepath"
"reflect"
"strings"
+
+ scalar "github.com/alexflint/go-scalar"
)
// spec represents a command line option
@@ -62,7 +64,7 @@ func Parse(dest ...interface{}) error {
// flags gets all command line arguments other than the first (program name)
func flags() []string {
- if len(os.Args) == 0 { // os.Args could be empty
+ if len(os.Args) == 0 {
return nil
}
return os.Args[1:]
@@ -442,3 +444,13 @@ func canParse(t reflect.Type) (parseable, boolean, multiple bool) {
return false, false, false
}
+
+// 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
+}
+
+// set a value from a string
+func setScalar(v reflect.Value, s string) error {
+ return scalar.ParseValue(v, s)
+}