Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import picocli.CommandLine.Help.Ansi.Text;
import picocli.CommandLine.Model.*;
import picocli.CommandLine.ParseResult.GroupMatchContainer;
import picocli.CommandLine.Spec;

import static java.util.Locale.ENGLISH;
import static picocli.CommandLine.Help.Column.Overflow.SPAN;
Expand Down Expand Up @@ -4488,7 +4489,7 @@ public enum ScopeType {
* @since 3.2
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD})
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
public @interface Spec {
/** Identifies what kind of {@code CommandSpec} should be injected.
* @since 4.3.0 */
Expand Down Expand Up @@ -7172,6 +7173,10 @@ Object[] commandMethodParamValues() {
CommandSpec autoHelpMixin = mixins.get(AutoHelpMixin.KEY);
int argIndex = autoHelpMixin == null || autoHelpMixin.inherited() ? 0 : 2;
for (int i = 0; i < methodParams.length; i++) {
if (methodParams[i].isAnnotationPresent(Spec.class)) {
values[i] = this;
continue;
}
if (methodParams[i].isAnnotationPresent(Mixin.class)) {
String name = methodParams[i].getAnnotation(Mixin.class).name();
CommandSpec mixin = mixins.get(empty(name) ? methodParams[i].name : name);
Expand Down Expand Up @@ -11990,6 +11995,9 @@ private static boolean initFromAnnotatedTypedMembers(TypedMember member,
commandSpec.addUnmatchedArgsBinding(buildUnmatchedForMember(member));
}
}
if (member.isAnnotationPresent(Spec.class) && member.isMethodParameter()) {
return false;
}
if (member.isArgSpec()) {
validateArgSpecMember(member);
if (groupBuilder != null) {
Expand Down Expand Up @@ -12024,7 +12032,10 @@ private static boolean initFromMethodParameters(IScope scope, Method method, Com
MethodParam param = new MethodParam(method, i);
if (param.isAnnotationPresent(Option.class) || param.isAnnotationPresent(Mixin.class) || param.isAnnotationPresent(ArgGroup.class)) {
optionCount++;
} else {
} else if (param.isAnnotationPresent(Spec.class)){
// Skipping the optionCount, since @Spec is not an option.
}
else {

param.position = i - optionCount;
}
Expand Down
Loading