Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to add additional parameter to repeatable ArgGroups with positional parameters #1050

Open
deining opened this issue May 16, 2020 · 1 comment
Labels
theme: arg-group An issue or change related to argument groups

Comments

@deining
Copy link
Contributor

deining commented May 16, 2020

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 ParameterIndexGapExceptionis thrown, however.

Side note:

Using the code above, I set mixinStandardHelpOptions = truefor 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.

@remkop
Copy link
Owner

remkop commented May 16, 2020

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).

@remkop remkop added the theme: arg-group An issue or change related to argument groups label May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: arg-group An issue or change related to argument groups
Projects
None yet
Development

No branches or pull requests

2 participants