dotnet / dotnet/command-line-api
Feature Request: Make the builtin validators public for easier initialization
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
## Story
As a developer, I want a simpler way to initialize an option's validations using property initializers.
```csharp
readonly Option Script = new("--script", "-c")
{
Description = "The PowerShell script to execute.",
Validator = {
FileOrDirectoryExists
}
};
```
Today I have to define it separately and then run `Script.AcceptLegalFileNamesOnly()` in a constructor, which is not ideal.
## Solution
Change the validators such as `FileOrDirectoryExists` https://github.com/dotnet/command-line-api/blob/702b2bbdd795ec978c3f2bb395a1a37442c13c8c/src/System.CommandLine/ArgumentValidation.cs to public so I can use them as shown above.
Contributor guide
Assessment
This issue has not been assessed yet.