Skip to content

fix #2760 - provide parser override via new Argument.CaptureRemainingTokens property#2783

Open
jonsequitur wants to merge 4 commits intodotnet:mainfrom
jonsequitur:fix-2760
Open

fix #2760 - provide parser override via new Argument.CaptureRemainingTokens property#2783
jonsequitur wants to merge 4 commits intodotnet:mainfrom
jonsequitur:fix-2760

Conversation

@jonsequitur
Copy link
Copy Markdown
Contributor

@jonsequitur jonsequitur commented Mar 13, 2026

This fixes #2760 by adding a new property currently named Argument.CaptureRemainingTokens.

I'm not sure this is the right name but the behavior is that this argument will capture everything following it regardless of whether it happens to match some well-known symbol. A few notes on this implementation:

  • It's intended to be used with enumerable types but this is not enforced.
  • It stops capturing when it reaches the arity limit for the argument. For this reason, a name like Greedy might be more accurate. Can we assume this term is intuitive enough?
  • The -- token has no special meaning when captured by an Argument with this property set to true. It gets captured as one of the tokens.

@baronfel @tmds Thoughts?

@jonsequitur jonsequitur requested a review from adamsitnik March 13, 2026 17:55
@KalleOlaviNiemitalo
Copy link
Copy Markdown

The -- token has no special meaning when captured by an Argument with this property set to true. It gets captured as one of the tokens.

That is what I would expect.

@KalleOlaviNiemitalo
Copy link
Copy Markdown

It's intended to be used with enumerable types but this is not enforced.

I imagine a custom parser could very well transform this token sequence to a non-enumerable type.

@jonsequitur jonsequitur requested a review from baronfel March 13, 2026 22:05
@jonsequitur jonsequitur changed the title fix #2760 fix #2760 - provide parser override via new Argument.CaptureRemainingTokens property Mar 31, 2026
Copy link
Copy Markdown
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

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

Since this is an implicit --, I started entertaining if we could take a different approach where we encapsulate the current double-dash implementation in a special-purpose Argument<string[]> that always captures all remaining tokens. That argument could be explicitly added to the CLI definition (as the last argument) to make the -- implicit, and if it's not already added to the CLI then we would add it with the "--" name.

An approach like that could prevent us from having 2 different mechanism for capturing the remaining tokens, and we could disallow that special argument from having a max capacity that can get filled up.

BUT after some feasibility research, I don't think it would come in very cleanly for a few reasons:

  1. Trying to encapsulate -- as an argument or option would affect tokenizing logic and how the remaining tokens are treated/exposed
  2. It would be challenging to make that change in a backwards-compatible manner for the existing UnmatchedTokens
  3. Would it be an Option or an Argument? Kind of both. Kind of neither.

I'm not convinced on the CaptureRemainingTokens name either, and I'm anxious about the complexity of filling to capacity and needing to spill over and that being potentially unintuitive. But this does plug in pretty cleanly overall.

I'll come back to this PR after thinking about it some more.

@jonsequitur
Copy link
Copy Markdown
Contributor Author

Yeah, the name CaptureRemainingTokens doesn't entirely convey one implication of the design, which is that an argument with this property set to true can still be limited by its arity. Another name I was weighing was Greedy which I think is reasonable as well. It conveys the sense that while other parsing rules (e.g. the names of options, or the -- token) might apply, this argument will override them.

@jonsequitur
Copy link
Copy Markdown
Contributor Author

Since this is an implicit --, I started entertaining if we could take a different approach where we encapsulate the current double-dash implementation in a special-purpose Argument<string[]> that always captures all remaining tokens.

We considered this design when we were changing the way -- worked. If I recall the conversation correctly, we decided that the -- is an escape mechanism and a feature of the grammar, and not a symbol in and of itself. Like POSIX bundling, it's there to meet end users' expectations and provide ecosystem consistency, not as an abstraction for developers.

It is appealing as a way to reduce concept count though.

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.

Make it possible for commands like dnx <toolname> to 'accrue' all tokens after <argname> for forwarding, not option-processing

3 participants