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
Allow an array of Classes in validateWith
and validateValueWith
#342
Conversation
I'm guessing this is backward compatible because the annotation syntax for attributes |
I'm new to jcommander. How should I test this ? can you please give me an example ? P. |
It's not a JCommander thing: if all the tests pass with your change, you're good. I was just initially surprised how such a change could be backward compatible and then I saw that you're only modifying the attribute type from a single value to an array. I was part of the annotation JSR and we specifically allowed "a = b" to be either a single value or an array, and that's probably why your code is backward compatible. Will review shortly. |
if (validator != null) { | ||
validateParameter(this, validator, name, value); | ||
Class<? extends IParameterValidator> validators[] = wrappedParameter.validateWith(); | ||
if (validators != null && validators.length>0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces: length > 0
.
if (validator != null) { | ||
validateValueParameter(validator, name, value); | ||
Class<? extends IValueValidator> validators[] = wrappedParameter.validateValueWith(); | ||
if (validators != null && validators.length>0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces.
public void multipleValidatorsFails1() | ||
{ | ||
ArgsMultiValidate a = new ArgsMultiValidate(); | ||
JCommander jc = new JCommander(a); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation.
public void multipleValidatorsFails2() | ||
{ | ||
ArgsMultiValidate a = new ArgsMultiValidate(); | ||
JCommander jc = new JCommander(a); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation.
|
||
public class ArgsMultiValidate { | ||
public static class OddIntegerParameterValidator implements IParameterValidator { | ||
@Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple indentations.
public static class OddIntegerParameterValidator implements IParameterValidator { | ||
@Override | ||
public void validate(String name, String value) throws ParameterException { | ||
if(Integer.parseInt(value)%2!=1) throw new ParameterException("param "+name+"="+value+" is not odd"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces.
back to you @cbeust. I hope I've fixed all the formatting problems :-) |
Looks good, thanks! |
Here is a PR where I've changed the definition of Parameter and DynamicParameter from:
to
this allow to specifiy multiple validator without creating a new class:
I've added a test and a paragraph in the documentation