Merge pull request #90 from alexflint/fix-89
Multiple args are terminated by "--"
This commit is contained in:
commit
873f3c2cf4
2
parse.go
2
parse.go
|
@ -502,7 +502,7 @@ func (p *Parser) process(args []string) error {
|
||||||
if spec.multiple {
|
if spec.multiple {
|
||||||
var values []string
|
var values []string
|
||||||
if value == "" {
|
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])
|
values = append(values, args[i+1])
|
||||||
i++
|
i++
|
||||||
if spec.separate {
|
if spec.separate {
|
||||||
|
|
|
@ -1045,3 +1045,15 @@ func TestVersion(t *testing.T) {
|
||||||
assert.Equal(t, ErrVersion, err)
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue