passing the no-more-options string "--" twice or more should pass the second and subsequent ones through as positionals
This commit is contained in:
parent
b218ad854d
commit
51d9bef113
2
parse.go
2
parse.go
|
@ -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
|
// must use explicit for loop, not range, because we manipulate i inside the loop
|
||||||
for i := 0; i < len(args); i++ {
|
for i := 0; i < len(args); i++ {
|
||||||
arg := args[i]
|
arg := args[i]
|
||||||
if arg == "--" {
|
if arg == "--" && !allpositional {
|
||||||
allpositional = true
|
allpositional = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -609,6 +609,15 @@ func TestNoMoreOptionsBeforeHelp(t *testing.T) {
|
||||||
assert.NotEqual(t, ErrHelp, err)
|
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) {
|
func TestHelpFlag(t *testing.T) {
|
||||||
var args struct {
|
var args struct {
|
||||||
Foo string
|
Foo string
|
||||||
|
|
Loading…
Reference in New Issue