-
Notifications
You must be signed in to change notification settings - Fork 408
Closed
Description
Calling AddError in the DefaultValueFactory will cause an exception when showing help
(provided the condition which triggers the error exists)
Help seemingly tries to create any default value, and in case it needs to call the AddError ( )-method
it tries to add to an internal structure which does not exist in "help-mode"
Probably it is not the best idea to add errors when creating default values
but then I took this example from the
Microsoft Tutorial
Option<FileInfo> fileOption = new("--file")
{
Description = "An option whose argument is parsed as a FileInfo",
Required = true,
DefaultValueFactory = result =>
{
if (result.Tokens.Count == 0)
{
return new FileInfo("sampleQuotes.txt");
}
string filePath = result.Tokens.Single().Value;
if (!File.Exists(filePath))
{
result.AddError("File does not exist");
return null;
}
else
{
return new FileInfo(filePath);
}
}
};