我使用 picocli(4.5.2)、lombok 和 guice 创建了一个 cli。我所有的命令类都有私有的最终字段(服务),它们是用 lombok 和 guice 初始化的。例如:
@Command(name = "example", helpCommand = true,
description = "example controller")
@RequiredArgsConstructor(onConstructor = @__({@Inject}))
public class ExampleCommand implements Callable<Integer> {
private final MyFacade myFacade;
@Setter
@ParentCommand
private ParentCommandHere parentCommandHere;
@Override
public Integer call() {
// do something
return 0;
}
}
我也有 picocli 文档中建议的 GuiceFactory 。
当我尝试使用 ManPageGenerator 生成文档时(使用以下文档)
我看到这个错误:
picocli.CommandLine$InitializationException: Cannot instantiate path.to.my.command.ExampleCommand : the class has no constructor
at picocli.CommandLine$DefaultFactory.create(CommandLine.java:5199)
at picocli.CommandLine$Model$CommandUserObject.getInstance(CommandLine.java:11160)
at picocli.CommandLine$Model$CommandSpec.userObject(CommandLine.java:5928)
at picocli.codegen.docgen.manpage.ManPageGenerator.traceAllSpecs(ManPageGenerator.java:312)
at picocli.codegen.docgen.manpage.ManPageGenerator.generateManPage(ManPageGenerator.java:285)
at picocli.codegen.docgen.manpage.ManPageGenerator.generateManPage(ManPageGenerator.java:300)
at picocli.codegen.docgen.manpage.ManPageGenerator.generateManPage(ManPageGenerator.java:300)
at picocli.codegen.docgen.manpage.ManPageGenerator$App.call(ManPageGenerator.java:215)
at picocli.codegen.docgen.manpage.ManPageGenerator$App.call(ManPageGenerator.java:166)
at picocli.CommandLine.executeUserObject(CommandLine.java:1933)
at picocli.CommandLine.access$1200(CommandLine.java:145)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2332)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2326)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2291)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2159)
at picocli.CommandLine.execute(CommandLine.java:2058)
at picocli.codegen.docgen.manpage.ManPageGenerator.main(ManPageGenerator.java:239)
Caused by: java.lang.NoSuchMethodException: path.to.my.command.ExampleCommand.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.getDeclaredConstructor(Class.java:2178)
at picocli.CommandLine$DefaultFactory.create(CommandLine.java:5174)
at picocli.CommandLine$DefaultFactory.create(CommandLine.java:5197)
有没有办法解决这个问题?