fix issue 89 (multiple args terminated by "--")

This commit is contained in:
Alex Flint 2019-10-04 13:18:17 -07:00
parent 8baf7040d7
commit 233d378a50
2 changed files with 13 additions and 1 deletions

View File

@ -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 {

View File

@ -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)
}