diff options
| author | Alex Flint <[email protected]> | 2017-02-15 18:19:41 -0800 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2017-02-15 18:19:41 -0800 |
| commit | 6859799559dab59729eb5fefeb53080db9b92545 (patch) | |
| tree | dd8a6476af78f555f067c923c815b78844161248 /parse.go | |
| parent | 765ccf745937c16486999600ecf789c646ac2e6c (diff) | |
use go-scalar, vendoring
Diffstat (limited to 'parse.go')
| -rw-r--r-- | parse.go | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -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) +} |
