dotnet / dotnet/command-line-api

`Command.Validators` should be invoked only when the command options are arguments are valid

Open
#2,779 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

For `Option` and `Argument`, custom validators are invoked before the conversion from the token (`string`) to `T`. It's well behavior for the use case such the production of better error messages, even so the behavior is not well documented (related #2645).

For `Command`, as same as above, validators are invoked before its options and arguments today, but it's useless.

I expect to be able to use `Command` validators for the **complex validation** of our command line. In other words, the options and arguments should be validated with their definitions (`Arity`, `AllowMultipleArgumentsPerToken`, `CustomParser`, etc, and `Validators`) first, then only when no one have any errors, the command validators should be invoked.

Or, reading the values of options and arguments from `Command.Validators` is incorrect? If so, better documentation is needed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.