Skip to content

fix: preserve tokens after StopOnNthArg boundary - #2455

Open
tianrking wants to merge 1 commit into
urfave:mainfrom
tianrking:codex/fix-stop-on-nth-arg-boundary
Open

tianrking wants to merge 1 commit into
urfave:mainfrom
tianrking:codex/fix-stop-on-nth-arg-boundary

Conversation

@tianrking

Copy link
Copy Markdown

What type of PR is this?

  • bug

What this PR does / why we need it:

StopOnNthArg checks its positional-argument boundary after the empty-token and -- branches. With a limit of one, exec host "" --verbose tail skips past the boundary and still sets verbose; exec host -- --verbose tail removes the separator before passing the arguments to the action.

Move the existing boundary check before token classification so all remaining arguments reach the action unchanged once the limit is reached.

  • command_parse.go: check the existing passthrough boundary before handling empty tokens or separators.
  • command_stop_boundary_test.go: cover root/subcommand boundaries, parsing controls, persistent flags and action lifecycle, and actual subprocess argv containing an empty argument or --.

Which issue(s) this PR fixes:

No existing issue found for this boundary case. It corrects the passthrough behavior introduced in #2163.

Special notes for your reviewer:

The change preserves normal flag parsing and separator handling before the configured boundary. Public API, dependencies, and generated API documentation are unchanged.

Testing

Original-source regression: 17 failing scenarios and four passing controls; the same final tests pass all 21 scenarios with the correction. The process cases execute the compiled test binary with real argv.

  • Exact-source native validation: Go 1.26.8 and 1.27.1 on Ubuntu 24.04, macOS 15, and Windows 2025; minimum Go 1.22.12 on Ubuntu. Original-source RED and fixed-source GREEN use the same tests in both build configurations. Full go test -race ./..., with and without urfave_cli_no_template, make vet, make check-binary-size, and make diffcheck pass. The full suites retain their existing six/twelve skipped tests; the added regression has no skips.
  • Quality and baseline comparison: make all, make test GFLAGS='--tags urfave_cli_no_template', goimports, golangci-lint 2.14.0 and formatter, make v3diff, and make diffcheck pass on both the original baseline and the correction. The generated API files are unchanged.
  • Actual gfmrun examples: argument basics, short options, and subcommand basics pass on both sources. The default make all gfmrun target currently checks a README containing no executable examples.

These fork runs check out source commit 9c76dcd12ecdc7d5542d7e522032a08fc6713674 and preserve the source hashes and clean tracked-file state before and after verification.

Release Notes

StopOnNthArg now preserves empty arguments and -- after the configured positional-argument boundary instead of continuing flag parsing or removing the separator.

@tianrking
tianrking requested a review from a team as a code owner October 4, 2026 21:54
@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Moves boundary check earlier in command-line argument parsing.

The PR appears safe to merge.

Summary

The PR moves the StopOnNthArg check ahead of token classification so arguments at and after the boundary reach the action unchanged.

  • Adds root, subcommand, persistent-flag, and subprocess regression coverage.
  • No actionable issues were identified.

Reviews (1) · Last reviewed commit: "fix: preserve tokens after StopOnNthArg ..."

@coilysiren

Copy link
Copy Markdown
Member

Good change, very easy to understand!

And also the type of thing someone might have a scripted reliance on. So I'll have to think about that.

Comment thread command_parse.go

// Once the boundary is reached, preserve all remaining tokens,
// including empty arguments and the double-dash separator.
if cmd.StopOnNthArg != nil && len(posArgs) == *cmd.StopOnNthArg {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just echo-ing my top level comment -

Good change, very easy to understand!

And also the type of thing someone might have a scripted reliance on. So I'll have to think about that.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants