From 233d378a5092a5c64c17f2ed9078dca9c09fcd47 Mon Sep 17 00:00:00 2001 From: Alex Flint Date: Fri, 4 Oct 2019 13:18:17 -0700 Subject: [PATCH] fix issue 89 (multiple args terminated by "--") --- parse.go | 2 +- parse_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/parse.go b/parse.go index 2a6b7c7..a29258a 100644 --- a/parse.go +++ b/parse.go @@ -502,7 +502,7 @@ func (p *Parser) process(args []string) error { if spec.multiple { var values []string if value == "" { - for i+1 < len(args) && !isFlag(args[i+1]) { + for i+1 < len(args) && !isFlag(args[i+1]) && args[i+1] != "--" { values = append(values, args[i+1]) i++ if spec.separate { diff --git a/parse_test.go b/parse_test.go index 882564e..5909472 100644 --- a/parse_test.go +++ b/parse_test.go @@ -1045,3 +1045,15 @@ func TestVersion(t *testing.T) { assert.Equal(t, ErrVersion, err) } + +func TestMultipleTerminates(t *testing.T) { + var args struct { + X []string + Y string `arg:"positional"` + } + + err := parse("--x a b -- c", &args) + require.NoError(t, err) + assert.Equal(t, []string{"a", "b"}, args.X) + assert.Equal(t, "c", args.Y) +}