Skip to content

feat: add PrefixCommandMode::PositionalOnly (#1374) - #1382

Open
henryiii wants to merge 1 commit into
mainfrom
fix/prefix-command-unknown-option-1374
Open

feat: add PrefixCommandMode::PositionalOnly (#1374)#1382
henryiii wants to merge 1 commit into
mainfrom
fix/prefix-command-unknown-option-1374

Conversation

@henryiii

@henryiii henryiii commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Fixes #1374.

Reworked per review: instead of reverting the 2.6.2 behavior, this keeps prefix_command(true) (PrefixCommandMode::On) as is — parsing stops at the first unrecognized item — and adds a new PrefixCommandMode::PositionalOnly.

In PositionalOnly mode, only a positional argument or the -- separator triggers prefix mode; an unrecognized option is collected as an extra and parsing continues. This is the pre-2.6.2 behavior as an opt-in mode, which is what ParaView/VTK depended on (they can switch to prefix_command(CLI::PrefixCommandMode::PositionalOnly)).

Includes tests for the new mode and README/docstring updates.

@henryiii

henryiii commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

@phlptp thoughts? This was changed in 2.6.2. We could introduce a new mode for the strict stop at any option mode. Or we could reintroduce the old mode, though that's more churn since this has only been out in one patch release. (This PR is just the revert, but any path is possible)

@phlptp

phlptp commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

the prefix_command mode has caused a bit of confusion over time. I remember several issues raised of it not working as expected and the previous behavior being confusing to people. So the previous behavior caused some issues and confusion, especially when used in combination with fallthrough and allow_extras. The current behavior made that clear to better match the documentation, but I guess there were those depending on the nuances of the behavior. I think the intended case is putting prefix_command on a subcommand with no option so that command dumps everything remaining since there are no valid options after that, or with a new mode using -- the complexity comes when adding prefix_command on an app/subcommand with existing options or fallthrough or allow_extras that it can interact with the parent options and get some odd behavior. I think my preference would be to leave the current behavior as is, as I would argue that it is clearer than before, and to address this issue add a PositionalOnly mode that turns off the while loop for unknown arguments.

@henryiii
henryiii marked this pull request as draft July 8, 2026 22:50
Keep the 2.6.2 behavior for prefix_command(true): parsing stops at the
first unrecognized item. Add a new PrefixCommandMode::PositionalOnly
that only stops at the first positional argument or the -- separator;
unrecognized options are collected as extras and parsing continues.
This gives the pre-2.6.2 behavior as an opt-in mode.

Assisted-by: ClaudeCode:claude-fable-5
@henryiii
henryiii force-pushed the fix/prefix-command-unknown-option-1374 branch from a804093 to 29832c7 Compare July 28, 2026 20:31
@henryiii henryiii changed the title fix: prefix_command should not stop parsing at unrecognized options (#1374) feat: add PrefixCommandMode::PositionalOnly (#1374) Jul 28, 2026
@henryiii

henryiii commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

Ahh, I wish it wouldn't auto-push. I'll comment or undraft when happy with it. Edit: looks pretty good, ready for review.

🤖 AI text below 🤖

Reworked as suggested: the revert is dropped, PrefixCommandMode::On keeps the current (2.6.2) behavior, and a new PrefixCommandMode::PositionalOnly provides the stop-only-at-positionals/-- behavior as an opt-in mode. Title and description updated.

@henryiii
henryiii marked this pull request as ready for review July 28, 2026 20:53
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.

App::prefix_command(true) changed behavior between // CLI11 2.5.0 and 2.6.2.

2 participants