summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2024-10-21 17:08:37 -0400
committerAlex Flint <[email protected]>2024-10-21 17:08:37 -0400
commit51d9bef113c82cff90c5929d28934bb241e1b1df (patch)
treeb1920fb274548c15efa8c97d2b04cf64c9addcdd
parentb218ad854d6817efffffa7f3d2cd3897498b28f6 (diff)
passing the no-more-options string "--" twice or more should pass the second and subsequent ones through as positionals
-rw-r--r--parse.go2
-rw-r--r--parse_test.go9
2 files changed, 10 insertions, 1 deletions
diff --git a/parse.go b/parse.go
index 172c7cd..d9c73d0 100644
--- a/parse.go
+++ b/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
for i := 0; i < len(args); i++ {
arg := args[i]
- if arg == "--" {
+ if arg == "--" && !allpositional {
allpositional = true
continue
}
diff --git a/parse_test.go b/parse_test.go
index 5bc781c..7e9cbf9 100644
--- a/parse_test.go
+++ b/parse_test.go
@@ -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