diff --git a/context.go b/context.go index c97aa84..2ed5d28 100644 --- a/context.go +++ b/context.go @@ -383,9 +383,13 @@ func (c *Context) trace(node *Node) (err error) { //nolint: gocyclo // Indicates end of parsing. All remaining arguments are treated as positional arguments only. case v == "--": - c.scan.Pop() c.endParsing() + // Pop the -- token unless the next positional argument accepts passthrough arguments. + if !(positional < len(node.Positional) && node.Positional[positional].Passthrough) { + c.scan.Pop() + } + // Long flag. case strings.HasPrefix(v, "--"): c.scan.Pop() diff --git a/kong_test.go b/kong_test.go index 7abf0ac..f05fc18 100644 --- a/kong_test.go +++ b/kong_test.go @@ -1743,10 +1743,16 @@ func TestPassthroughArgs(t *testing.T) { []string{"something"}, }, { - "DashDashBeforeRecognizedFlag", + "DashDashBetweenArgs", + []string{"foo", "--", "bar"}, + "", + []string{"foo", "--", "bar"}, + }, + { + "DashDash", []string{"--", "--flag", "foobar"}, "", - []string{"--flag", "foobar"}, + []string{"--", "--flag", "foobar"}, }, { "UnrecognizedFlagAndArgs",