Skip to content

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

Open

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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