Repository navigation
Conversation
|
|
With TraverseChildren, the long-flag branch of Traverse matched a bare -- as a flag that takes a value. It appended -- to the accumulated flags, set inFlag=true (because arg[2:] is empty and no flag with that name exists), consumed the next positional as the flag's value, and then let the following positional match a subcommand name. The child handler then ran, the first post-`--` positional was silently dropped, and the parent's positionals never reached the chosen command. Mirror the behaviour of the default stripFlags path and stop command discovery as soon as -- is seen. Return the current command and the remaining args starting at the delimiter so a downstream parser sees the exact slice it would have gotten without TraverseChildren. Fixes spf13#2528.
piyush295
force-pushed
the
fix/traverse-stop-at-double-dash
branch
from
October 16, 2026 09:26
c783ca0 to
944515d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug (fixes #2528)
With
TraverseChildren: true, the long-flag branch ofCommand.Traversematched a bare--as a flag that "takes a value":arg[2:]is"", no flag by that name exists, soinFlag = true. The next positional is consumed as that flag's "value" and the following positional happens to match a subcommand — so the child handler runs, the first post---positional is silently dropped, and the parent's positionals never reach any command.Reproduction from the issue:
The default (non-traverse)
stripFlagspath already stops command discovery on--.Fix
Mirror that behaviour. When
Traversesees a bare--:TraverseChildren.Test
TestTraverseStopsAtEndOfFlagscovers two cases:[]string{"--", "literal", "child"}→ traversal stays on root, remaining is unchanged.[]string{"--", "child"}→ traversal stays on root, remaining is unchanged.go test ./...is green.