-
Notifications
You must be signed in to change notification settings - Fork 400
[Proposal] Remove TreatUnmatchedTokensAsErrors
#2350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The
In It could still become a problem in other applications that dynamically build parsers. But that doesn't mean |
Can you comment on this - how we do it, how we want to do it, and whether we could make a change without breaking the world. |
Does anyone besides Background:
|
The usual use case for this that I've seen is that after a certain point on the command line, a second parser will be taking over, possibly in another process.
|
FWIW we've long since fixed our incorrect usage of |
@KathleenDollard We need this API in There we are parsing a command line with unknown structure and passing some arguments through to an arbitrary subcommand that dotnet-watch invokes. I'd prefer better APIs to do so, one that would be easier to use and handle Perhaps having a special CliCommand that servers as a placeholder for an arbitrary command and all options and arguments following it get associated with it might work. |
The alternative approach to unmatched tokens is to create a command with an argument that is a collection of strings. Those strings would then be the args passed to the command. I believe that I am looking for cases where that approach would fail. We will definitely support handing off to other parsers.
Just want to clarify whether this is just making it easy to create |
I'm a bit new here but I have been a big fan of SCL since I first found it about two years ago. I think I agree with getting rid of
If I understand correctly, let's say I have a CLI program If what I wrote above is accurate in my understanding, then I would advocate for Now, my current understanding is that it is proposed that this is all somewhat implicitly done by the parser? But I wonder if this should be a more explicit choice by the CLI author? So, when defining var bar = new Command("bar");
bar.AddExtraArgumentOption(required: false); // the default value of required is false OK, I don't quite like that name, but why do I propose this? Because now you have no unmatched tokens at all. It's expected that there could be a One thing that might gum up the works here is if So, imagine a tree of commands: graph LR
A([foo]) --> B([bar]);
A --> C([baz]);
C --> D([qux]);
If graph LR
A([foo]) --> B([bar])
A --> C([baz])
A --> D[--]
C --> E([qux])
The values supplied to the argument of the However, if var bar = new Command('bar').AddExtraArgumentOption();
var baz = new Command('baz').AddExtraARgumentOption(); And again, of course, graph LR
A([foo]) --> B([bar])
A --> C([baz])
B --> D[--]
C --> E([qux])
C --> F[--]
It should also be noted that there are some CLI applications that will happily run to successful completion even with extra "unmatched" (and unused) tokens (though, those are usually superfluous and don't usually follow a graph LR
A([foo]) --> B([bar])
A --> C([baz])
A --> D[--]
D --> E[/arguments/]
A --> F[/"`_*unmatched*_ arguments`"/]
So that's why I think that I agree with removing |
In the same spirit as asking "why" on custom parsers, we are asking "why" on
TreatUnmatchedTokensAsErrors
.The major reason, and the one used by
dotnet new
anddotnet msbuild
is to compose CLIs. The args not used by the .NET CLI are passed to the additional parser. In the case ofdotnet new
it builds a dynamic parser based on the template chosen (very cool stuff).msbuild
still has its own parser.We've found that this is better handled by creating an
CliArgument
that is an array of strings and passing that array along to the other parser.One of the reasons
TreatUnmatchedTokensAsErrors
feels uncomfortable because it leads to exposing the Token type outside the parser layer. It seems preferable to make this an internal type. There also may be an implication that you can have unmatched tokens anywhere in the CLI, but in general, once unmatched tokens appear, parsing can become complicated and problematic.The proposal is to remove it.
We look forward to hearing about any scenarios that are not covered by a collection of strings as an argument on the command that should route to a composed CLI.
The text was updated successfully, but these errors were encountered: