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

An IParametersValidator on an ParametersDelegate should not be lifted to the top-level object #575

Open
ekpdt opened this issue Jan 3, 2024 · 2 comments
Labels
bug Bug

Comments

@ekpdt
Copy link

ekpdt commented Jan 3, 2024

Take the following example:

  @Parameters(parametersValidators = MyValidator.class)
  static final class SubGroup {
    @Parameter(names = "--arg1")
    private boolean arg1;

    @Parameter(names = "--arg2")
    private String arg2;
  }

  static final class ArgsTop {
    @Parameter(names = "--argtop")
    private boolean argtop;

    @ParametersDelegate
    private SubGroup subGroup = new SubGroup();
  }

  public static void main(String[] args) {
    var args = new ArgsTop();
    JCommander.newBuilder().addObject(args).build();  // MyValidator::validate invoked reflectively here.
  }

When MyValidator::validate is invoked, it should only see entries for arg1 and arg2, not argtop.
This would make it much easier to implement generic mutex groups. I think it would also be more intuitive.

@mkarg
Copy link
Collaborator

mkarg commented Feb 18, 2024

Feel free to contribute a PR including a test, but note that we must stay backwards compatible unless we move on to jCommander 2.x. OTOH I think we could safely say that it is a bug that MyValidator can see argtop. So I would rate your contribution as a bug fix, which we can include in 1.x.

@mkarg mkarg added the bug Bug label Feb 18, 2024
@mkarg
Copy link
Collaborator

mkarg commented Apr 27, 2024

@ekpdt Elan, still looking forward to receive your PR. Still working on it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug
Projects
None yet
Development

No branches or pull requests

2 participants