Skip to content

Commit

Permalink
Merge pull request #273 from alexflint/pass-dash-dash-through
Browse files Browse the repository at this point in the history
Passing the no-more-options string "--" twice or more
  • Loading branch information
alexflint authored Nov 4, 2024
2 parents b218ad8 + 51d9bef commit efb1be7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ func (p *Parser) process(args []string) error {
// must use explicit for loop, not range, because we manipulate i inside the loop
for i := 0; i < len(args); i++ {
arg := args[i]
if arg == "--" {
if arg == "--" && !allpositional {
allpositional = true
continue
}
Expand Down
9 changes: 9 additions & 0 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,15 @@ func TestNoMoreOptionsBeforeHelp(t *testing.T) {
assert.NotEqual(t, ErrHelp, err)
}

func TestNoMoreOptionsTwice(t *testing.T) {
var args struct {
X []string `arg:"positional"`
}
err := parse("-- --", &args)
require.NoError(t, err)
assert.Equal(t, []string{"--"}, args.X)
}

func TestHelpFlag(t *testing.T) {
var args struct {
Foo string
Expand Down

0 comments on commit efb1be7

Please sign in to comment.