summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2017-09-27 14:56:33 -0700
committerGitHub <[email protected]>2017-09-27 14:56:33 -0700
commit398a01ebab8b6260be8714a39ad19ecb0db58dc1 (patch)
treee5b3f4606f5015f156281795f4531ab1664450e0
parentcef6506c97e5731da728c374ff3523e481026423 (diff)
parentfb97335a13312831f89c8b88b898701c7c8233b9 (diff)
Merge pull request #57 from rickb777/master
Allow spaces after each comma in tags
-rw-r--r--parse.go1
-rw-r--r--parse_test.go16
2 files changed, 14 insertions, 3 deletions
diff --git a/parse.go b/parse.go
index ecbb7e4..ee10387 100644
--- a/parse.go
+++ b/parse.go
@@ -168,6 +168,7 @@ func NewParser(config Config, dests ...interface{}) (*Parser, error) {
// Look at the tag
if tag != "" {
for _, key := range strings.Split(tag, ",") {
+ key = strings.TrimLeft(key, " ")
var value string
if pos := strings.Index(key, ":"); pos != -1 {
value = key[pos+1:]
diff --git a/parse_test.go b/parse_test.go
index a646f2b..55f3fa6 100644
--- a/parse_test.go
+++ b/parse_test.go
@@ -131,7 +131,7 @@ func TestMixed(t *testing.T) {
var args struct {
Foo string `arg:"-f"`
Bar int
- Baz uint `arg:"positional"`
+ Baz uint `arg:"positional"`
Ham bool
Spam float32
}
@@ -341,9 +341,9 @@ func TestMissingRequired(t *testing.T) {
assert.Error(t, err)
}
-func TestMissingRequiredMultiplePositional(t *testing.T) {
+func TestNonsenseKey(t *testing.T) {
var args struct {
- X []string `arg:"positional, required"`
+ X []string `arg:"positional, nonsense"`
}
err := parse("x", &args)
assert.Error(t, err)
@@ -821,3 +821,13 @@ func TestSeparatePositionalInterweaved(t *testing.T) {
assert.Equal(t, "zzz", args.Pre)
assert.Equal(t, []string{"post1", "post2", "post3"}, args.Post)
}
+
+func TestSpacesAllowedInTags(t *testing.T) {
+ var args struct {
+ Foo []string `arg:"--foo, -f, separate, required, help:quite nice really"`
+ }
+
+ err := parse("--foo one -f=two --foo=three -f four", &args)
+ require.NoError(t, err)
+ assert.Equal(t, []string{"one", "two", "three", "four"}, args.Foo)
+}