dotnet / dotnet/command-line-api

Argument<DirectoryInfo> with default value isn't validated with ExistingOnly()

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

Description

In the following example, if an argument is NOT provided then the `.ExistingOnly()` requirement is not applied:

```csharp
new Option(new[] {"--output", "-o"}, "folder to output the things to")
{
Argument = new Argument(() => new DirectoryInfo("things"))
{
Arity = ArgumentArity.ExactlyOne
}.ExistingOnly()
}
```

In the above, the folder named `things` does not exists so a validation error was expected but was not raised.

Whereas if an argument is passed which refers to a non-existent folder then I get the expected error:

```
Directory does not exist: folder-which-does-not-exist
```

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.