Description
Currently, Argument.GetRequiredValue
and Option.GetRequiredValue
will throw InvalidOperationException
when the argument or option wasn't actually parsed from command line input. For example:
var option = new Option<bool>("-x");
var command = new RootCommand
{
option
};
// the following throws: -x is required but was not provided
var value = command.Parse("").GetRequiredValue(option);
If Option.DefaultValueFactory
is set, then the exception is not thrown.
I believe the design of GetValue
and GetRequiredValue
should focus on whether the value for the symbol can be bound, including implicit and default values, regardless of whether a matching token was found on the parsed commandline.
This could be the wrong intuition though. For bool
it seems intuitive, and perhaps for int
and other numeric types that default to 0
, but for more complex structs such as DateTime
, as well as for reference types, this kind of behavior seems nonsensical.
What are people's thoughts on this?