Fix implied boolean arity, even if annotation is used

Fixes #83
This commit is contained in:
Eric Bottard
2017-06-02 10:45:16 +02:00
parent 33c1474216
commit ecd27de09a
2 changed files with 9 additions and 3 deletions

View File

@@ -37,6 +37,11 @@ public @interface ShellOption {
String NONE = "__NONE__";
/**
* Marker value to indicate that heuristics should be used to derive arity.
*/
int ARITY_USE_HEURISTICS = -1;
/**
* The key(s) (without the {@link ShellMethod#prefix()}) by which this parameter can be referenced
* when using named parameters. If none is specified, the actual method parameter name will be used.
@@ -44,9 +49,10 @@ public @interface ShellOption {
String[] value() default {};
/**
* Return the number of input "words" this parameter consumes.
* Return the number of input "words" this parameter consumes. Default is 1, except when parameter type is boolean,
* in which case it is 0.
*/
int arity() default 1;
int arity() default ARITY_USE_HEURISTICS;
/**
* The textual (pre-conversion) value to assign to this parameter if no value is provided by the user.

View File

@@ -371,7 +371,7 @@ public class StandardParameterResolver implements ParameterResolver {
private int getArity(Parameter parameter) {
ShellOption option = parameter.getAnnotation(ShellOption.class);
int inferred = (parameter.getType() == boolean.class || parameter.getType() == Boolean.class) ? 0 : 1;
return option != null ? option.arity() : inferred;
return option != null && option.arity() != ShellOption.ARITY_USE_HEURISTICS ? option.arity() : inferred;
}
/**