dotnet / dotnet/command-line-api

Invalid default value for option is not considered as parse error

Open
#1,474 7 comments 0 reactions 0 assignees View on GitHub
Area-Parser and Binder
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

When setting wrong value for default option, it is not considered as parse error, see below.
It would be good to have it as parse error or reflected in option result somehow.

```C#
Command myCommand = new Command("test");
var intOption = new Option("--opt")
{
Arity = new ArgumentArity(1, 1)
};
intOption.SetDefaultValue("not-int");
myCommand.AddOption(intOption);
var parseResult = myCommand.Parse("test");

Assert.NotEmpty(parseResult.Errors); //fails, no parse errors
var optionResult = parseResult.FindResultFor(intOption); //not null
var optionValue = parseResult.GetValueForOption(intOption); //throws, probably as expected
```

On other note, parse argument delegate is not called when option is not specified, so it is not possible to customize this behavior.

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.