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

ArgGroups with validate=false should be non-exclusive #833

Closed
remkop opened this issue Oct 10, 2019 · 0 comments
Closed

ArgGroups with validate=false should be non-exclusive #833

remkop opened this issue Oct 10, 2019 · 0 comments
Labels
theme: arg-group An issue or change related to argument groups type: enhancement ✨
Milestone

Comments

@remkop
Copy link
Owner

remkop commented Oct 10, 2019

(Related to #810)

If an Argument Group is defined as @ArgGroup(validate = false), it should automatically be set to exclusive = false.

This prevents issues where a new group instance is created for each option in the group. This is not necessary for non-validating groups.

For example:

@ArgGroup(validate = false, exclusive = true, heading = "...%n")
MyGroup group = new MyGroup();

static class MyGroup {
    @Option(names = "-a", required = true)
    boolean a;

    @Option(names = "-b", required = true)
    boolean b;
}

When the user specifies -a -b, the application expects to be able to inspect the group and see both the a and the b field set to true. For exclusive groups this won't happen. While parsing, when the second option of an exclusive group is matched, a new instance of the group is created to prevent having mutually exclusive options in the same group. So, in the above example, the group field would be reassigned a new instance of MyGroup, and only the b field in that instance would be true.

The fix is to automatically set groups to exclusive = false when the group is defined as non-validating.

@remkop remkop added this to the 4.1 milestone Oct 10, 2019
@remkop remkop added the theme: arg-group An issue or change related to argument groups label Oct 10, 2019
@remkop remkop closed this as completed in f5e67af Oct 10, 2019
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 type: enhancement ✨
Projects
None yet
Development

No branches or pull requests

1 participant