Skip to content

Feature Request: Make the builtin validators public for easier initialization #2766

@JustinGrote

Description

@JustinGrote

Story

As a developer, I want a simpler way to initialize an option's validations using property initializers.

readonly Option<string> Script = new("--script", "-c")
{
  Description = "The PowerShell script to execute.",
  Validator = {
    FileOrDirectoryExists<FileInfo>
  }
};

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<T> https://github.com/dotnet/command-line-api/blob/702b2bbdd795ec978c3f2bb395a1a37442c13c8c/src/System.CommandLine/ArgumentValidation.cs to public so I can use them as shown above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions