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

# Powderhouse Validation #2476

Open KathleenDollard opened 1 month ago

KathleenDollard commented 1 month ago

This is a draft of the validation design that was discussed this week. This is part of the outcome of issues raised in #2458.

Powderhouse validation is intended to make the easy stuff easy and predictable, and be able to extend what is easy, with decent performance. This is accomplished with several moving parts, with the expectation that the CLI author will only need to know about the extension methods (likely later extension properties) that appear in their IntelliSense.

We also want to:

Annotation collections

Annotation collections are expected to be added to the annotation system.

Currently AnnotationIds identify single values. If that value is not found in the default provider (strongly typed weak table), additional providers are queried until the first value is found.

Annotation collections also use an AnnotationId to identify values. However, each provider may include a collection of values and the returned value is a collection of all those values.

The two known use cases are ValueConditions and examples.

ValueCondition

Validation determines whether expectations about the values supplied for symbols are met. Those expectations can also drive completions and contribute to rich help. Thus, the definition of what should be validated (such as a range) is held in ValueCondition and the annotation collection for the value condition annotation Id derive from the abstract class ValueCondition.

Extension methods

CLI authors will rarely if ever create ValueConditions. Instead extension methods on symbol allow syntax like:

myOption.AddRange(1,5);

ValidationSubsystem

A ValidationSubsystem is held by the pipeline and called to perform validation. It holds a set of validators.

Validators

Validators derive from the abstract Validator class and perform validation. Validators have a name for debugging, and a set of ValueConditon types that they can validate.

Flow (with pipeline)