-
Notifications
You must be signed in to change notification settings - Fork 446
Closed
Labels
theme: parserAn issue or change related to the parserAn issue or change related to the parsertype: bug 🐛
Milestone
Description
Observed behaviour
For positional parameters, defining arity with a variable, like this: @Parameters(arity = "${xxx:-1..*}") has a bug:
regardless of the value of the system property xxx, the positional parameter is never mandatory/required.
Expected behaviour
if system property xxx is not defined, the default arity of 1..* means that at least one value is required. But this is not enforced.
How to reproduce
@Test(expected = CommandLine.MissingParameterException.class)
public void testRequiredPositionalWithUndefinedVariable() {
class Cmd {
@Parameters(arity = "${xxx1:-1..*}") List<String> positional;
}
new CommandLine(new Cmd()).parseArgs(); // should fail with missing param but doesn't
}Analysis:
ArgSpec.required is derived from arity.min > 0, without considering whether the arity Range object has unresolved variables.
Any variables in the ArgSpec's arity are not resolved until the ArgSpec is added to its CommandSpec.
At this point, the ArgSpec's arity is replaced by a new Range object with valid values, but the ArgSpec's required attribute is not updated.
Metadata
Metadata
Assignees
Labels
theme: parserAn issue or change related to the parserAn issue or change related to the parsertype: bug 🐛