dotnet / command-line-api

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

Added Calculated Symbols and improved ValueProvider #2483

Closed KathleenDollard closed 2 weeks ago

KathleenDollard commented 1 month ago

Creating CalculatedSymbol exposed flaws in the ValueProvider logic, so I went ahead and added the check for reentrancy. These can be severed if needed.

I also started an OpenQuestions document so we can scribble notes.

Calculated values

The benefits of calculated values:

This is a sufficiently small amount of work, that I would recommend it even if only because it solves the nuget why problem so elegantly.

Other notes on the PR

There are also test for dotnet nuget why which in ValueProviderTests. In this case one array input is split into two values.

I think CalculatedValues, along with dependent value sources for validation, will accommodate the majority of current use of custom parsers (which we do not plan to support).

We should discuss the API for CalculatedValue with multiple input symbols. This is needed for the compositing problem, which is demonstrated by the Point2D test in ValueProviderTests. This is particularly ugly because RelativeToSymbolValueSource nad RelativeToSymbolsValueSource have a different order of parameters due to params and default values. However, there is first a deeper discussion on whether it should be multiple symbols, or an aggregate that can handle any ValueSource. For example, it is an easy hop from where we are in this PR to a value that relies on a combination of calculations with no dependency (such as offsets from today), values that are calculated relative to another symbol, and ones that are relative to an environment variable. It's all just how we allow people to use ValueSource

KathleenDollard commented 1 month ago

I made some naming changes that were really bothering me, and clarified how collection value sources work, which will hopefully help differentiate the collection value source and FallbackValueSource. I look forward to further discussions of the API.

KathleenDollard commented 2 weeks ago

Per discussions with Mikayla, we want to explore using custom type providers in the core layer to solve the problems calculated values is solving in the subsystem layer in this PR.

For clarity, I am closing this PR and replacing it with a PR that has the other work that was included in this PR.