-
Notifications
You must be signed in to change notification settings - Fork 441
Open
Labels
theme: annotation-procAn issue or change related to the annotation processorAn issue or change related to the annotation processortype: bug 🐛
Milestone
Description
Hello, the following piece of code is working with picocli 4.7.6 (with annoation processsor enabled), but breaks in 4.7.7. The goal is to have a reusable ArgGroup
with custom header, so I can @Mixin
it wherever it's needed. In case my approach was wrong, what's the intended way to achieve it?
Test code:
import picocli.CommandLine;
import java.util.concurrent.Callable;
@CommandLine.Command(name = "main")
class Main implements Callable<Integer> {
static class Options {
@CommandLine.Spec
CommandLine.Model.CommandSpec spec;
int option1 = 1;
int option2 = 2;
@CommandLine.Option(names = "-o1")
void setOption1(int value) {
if (value > 10) {
throw new CommandLine.ParameterException(spec.commandLine(), "option1 must be <= 10");
}
this.option1 = value;
}
@CommandLine.Option(names = "-o2")
void setOption2(int value) {
if (value > 10) {
throw new CommandLine.ParameterException(spec.commandLine(), "option2 must be <= 10");
}
this.option2 = value;
}
}
static class ArgGroup {
@CommandLine.ArgGroup(exclusive = false, heading = "Shared options%n")
Options options = new Options();
}
@CommandLine.Mixin
ArgGroup argGroup = new ArgGroup();
@Override
public Integer call() throws Exception {
System.out.printf("Hello world: o1 = %s, o2 = %s%n",
argGroup.options.option1,
argGroup.options.option2
);
return 0;
}
public static void main(String[] args) {
int exitCode = new CommandLine(new Main())
.execute(args);
System.exit(exitCode);
}
}
Expected output: it works just like in 4.7.6.
Actual output:
java: @Spec must be enclosed in a @Command, or in a class that implements IVersionProvider but was Main.Options: Options
Note that it seems to work at runtime with annotation processor disabled.
Run with: -h
Output:
Unknown option: '-h'
Usage: main [[-o1=<option1>] [-o2=<option2>]]
Shared options
-o1=<option1>
-o2=<option2>
Run with: -o1 7 -o2 8
Output:
Hello world: o1 = 7, o2 = 8
Run with: -o1 11 -o2 1
Output:
option1 must be <= 10
Usage: main [[-o1=<option1>] [-o2=<option2>]]
Shared options
-o1=<option1>
-o2=<option2>
Metadata
Metadata
Assignees
Labels
theme: annotation-procAn issue or change related to the annotation processorAn issue or change related to the annotation processortype: bug 🐛