You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Why Option exposes IsRequired while it also exposes Arity? #2082
Option.Arity describes how many argument tokens the option requires if the option is provided. It only has significance when the option is present on the command line being parsed.
Option.IsRequired indicates whether an option must be provided. Only when it's provided are the arity rules meaningful.
@jonsequitur how does it work when it comes to Argument, which exposes Arity but no IsRequired?
Currently the RequiredArgumentMissing error is reported for the CommandResult which owns Argument, rather than for the ArgumentResult itself (it's not created at all).
Because of that, ParseResult.FindResultFor(argument) returns null and ParseResult.GetValue(argument) returns default.
Activity
jonsequitur commentedon Mar 7, 2023
Option.Aritydescribes how many argument tokens the option requires if the option is provided. It only has significance when the option is present on the command line being parsed.Option.IsRequiredindicates whether an option must be provided. Only when it's provided are the arity rules meaningful.adamsitnik commentedon Mar 8, 2023
@jonsequitur how does it work when it comes to
Argument, which exposesAritybut noIsRequired?Currently the
RequiredArgumentMissingerror is reported for theCommandResultwhich ownsArgument, rather than for theArgumentResultitself (it's not created at all).Because of that,
ParseResult.FindResultFor(argument)returnsnullandParseResult.GetValue(argument)returnsdefault.This seems to be by design:
command-line-api/src/System.CommandLine.Tests/Binding/TypeConversionTests.cs
Lines 947 to 960 in c63e231
but it's not intuitive for me (we have a parse error related to given argument, but it's not thrown when value is being requested).
jonsequitur commentedon Mar 8, 2023
Options are optional by default, whereas arguments are required by default.
The test does look wrong. The default arity for that argument is {1,1} which means there should be an error there.
adamsitnik commentedon Mar 8, 2023
@jonsequitur big thanks for all the answers, they were very helpful!