picocli
picocli copied to clipboard
Unable to add additional parameter to repeatable ArgGroups with positional parameters
As of picocli 4.3, repeatable ArgGroups can now define positional parameters. I'm encountering difficulties while using this new feature:
import java.util.List;
import picocli.CommandLine;
import picocli.CommandLine.*;
@Command(name = "grades")
public class RepeatableGroupsDemo implements Runnable {
static class StudentGrade {
@Parameters(index = "0") String name;
@Parameters(index = "1") int grade;
}
@ArgGroup(exclusive = false, multiplicity = "2")
List<StudentGrade> gradeList;
@Parameters(index="2", arity = "1")
private String code;
@Override
public void run() {
}
public static void main(String[] args) {
System.exit(new CommandLine(new RepeatableGroupsDemo()).execute("Joe", "3", "John", "4", "aCode"));
}
}
When running this code, I'm getting:
Missing required parameter: '<code>'
Usage: grades (<name> <grade>) (<name> <grade>) <code>
Is this the intended behaviour? Is there any way to make this work? I think the last parameter is supposed to be marked with index=4
. When specifiying @Parameters(index="4", arity = "1")
, a ParameterIndexGapException
is thrown, however.
Side note:
Using the code above, I set mixinStandardHelpOptions = true
for the command. Usage help is now:
Usage: grades (<name> <grade>) (<name> <grade>) [-hV] <code>
The option [-hV]
is printed in between the parameters, which is unfortunate IMHO.
Yes, there are some @Ignore
-ed tests in ArgGroupTest
for cases like this, where positional parameters are defined inside a group as well as outside one. It is documented as one of the limitations of argument groups.
I briefly looked at it but have not spent that much time on it. It may be difficult to get this to work...
The note about the synopsis is also interesting. Looks like a separate issue. That one should be fixable (but haven't looked in detail).