dotnet / command-line-api

Command line parsing, invocation, and rendering of terminal output.
https://github.com/dotnet/command-line-api/wiki
MIT License
3.34k stars 375 forks source link

Consider where arity checks should occur #2418

Open KathleenDollard opened 2 months ago

KathleenDollard commented 2 months ago

In the case of a specific upper bound arity other than 1 or a large number, parsing is affected by the upper bound arity. It is also affected by a zero only arity. Because of this, arity needs to be available for CliOption and CliArgument during parsing.

Question 1: Should CLI authors be able to define arity in raw parser scenarios?

If we do not allow this, it would be settable from pipelines only.

Pros of allowing definition:

Cons of allowing definition:

Question 2: Should we create non-critical arity issues in raw parser scenarios?

Pros of creating:

Cons of creating:

Question 2: Should we report non-critical arity issues in raw parser scenarios?

We need to get this decision right. Changing it would be a breaking change in CLIs.

Pros of reporting:

Cons of reporting:

Proposal

One way to work around the issues above is the following.

The result is that ParseResult is the sole source of critical errors, and PipelineResult is the best source for validation errors.

This is not perfect because the same condition could (and perhaps generally would) result in a different error in ParseResult and PipelineResult. While this is weird, it allows raw parser usage to receive errors we know about while the pipeline validation reporting remains self consistent and in the control of the current validation subsystem. 

I wrote this proposal because my head was screaming every time I saw validation in the parser.