Merge pull request #57 from rickb777/master
Allow spaces after each comma in tags
This commit is contained in:
commit
398a01ebab
1
parse.go
1
parse.go
|
@ -168,6 +168,7 @@ func NewParser(config Config, dests ...interface{}) (*Parser, error) {
|
||||||
// Look at the tag
|
// Look at the tag
|
||||||
if tag != "" {
|
if tag != "" {
|
||||||
for _, key := range strings.Split(tag, ",") {
|
for _, key := range strings.Split(tag, ",") {
|
||||||
|
key = strings.TrimLeft(key, " ")
|
||||||
var value string
|
var value string
|
||||||
if pos := strings.Index(key, ":"); pos != -1 {
|
if pos := strings.Index(key, ":"); pos != -1 {
|
||||||
value = key[pos+1:]
|
value = key[pos+1:]
|
||||||
|
|
|
@ -131,7 +131,7 @@ func TestMixed(t *testing.T) {
|
||||||
var args struct {
|
var args struct {
|
||||||
Foo string `arg:"-f"`
|
Foo string `arg:"-f"`
|
||||||
Bar int
|
Bar int
|
||||||
Baz uint `arg:"positional"`
|
Baz uint `arg:"positional"`
|
||||||
Ham bool
|
Ham bool
|
||||||
Spam float32
|
Spam float32
|
||||||
}
|
}
|
||||||
|
@ -341,9 +341,9 @@ func TestMissingRequired(t *testing.T) {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMissingRequiredMultiplePositional(t *testing.T) {
|
func TestNonsenseKey(t *testing.T) {
|
||||||
var args struct {
|
var args struct {
|
||||||
X []string `arg:"positional, required"`
|
X []string `arg:"positional, nonsense"`
|
||||||
}
|
}
|
||||||
err := parse("x", &args)
|
err := parse("x", &args)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
@ -821,3 +821,13 @@ func TestSeparatePositionalInterweaved(t *testing.T) {
|
||||||
assert.Equal(t, "zzz", args.Pre)
|
assert.Equal(t, "zzz", args.Pre)
|
||||||
assert.Equal(t, []string{"post1", "post2", "post3"}, args.Post)
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue