dotnet / dotnet/command-line-api
Invalid default value for option is not considered as parse error
- 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
Assessment
This issue has not been assessed yet.