dotnet / dotnet/command-line-api

Feature Request: Make the builtin validators public for easier initialization

Open
#2,766 0 comments 0 reactions 0 assignees View on GitHub
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

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.