Skip to content
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

Add support for @Command-annotated methods to codegen tools (was:ManPageGenerator: Can't find annotated method) #1858

Open
msgilligan opened this issue Oct 24, 2022 · 1 comment
Labels
status: help-wanted 🆘 theme: codegen An issue or change related to the picocli-codegen module type: enhancement ✨

Comments

@msgilligan
Copy link

msgilligan commented Oct 24, 2022

I'm using picocli 4.6.3 with Gradle.

I had a class method annotated with @Command that worked properly, but when I tried to generate a man page for it, I got the following error:

picocli.codegen.docgen.manpage.ManPageGenerator org.consensusj.ledgerexport.tool.WalletAccountingExport --outdir=/Users/sean/git/WalletLedgerExport/ledger-export-tool/build/generated-picocli-docs -v
Successfully started process 'command '/Users/sean/.sdkman/candidates/java/17.0.4.1-tem/bin/java''
picocli.CommandLine$InitializationException: class org.consensusj.ledgerexport.tool.WalletAccountingExport is not a command: it has no @Command, @Option, @Parameters or @Unmatched annotations
        at picocli.CommandLine$Model$CommandReflection.validateCommandSpec(CommandLine.java:11680)
        at picocli.CommandLine$Model$CommandReflection.extractCommandSpec(CommandLine.java:11510)
        at picocli.CommandLine$Model$CommandSpec.forAnnotatedObject(CommandLine.java:6236)
        at picocli.CommandLine.<init>(CommandLine.java:227)
        at picocli.CommandLine.<init>(CommandLine.java:221)
        at picocli.codegen.util.Util.getCommandSpecs(Util.java:22)
        at picocli.codegen.docgen.manpage.ManPageGenerator$App.call(ManPageGenerator.java:214)
        at picocli.codegen.docgen.manpage.ManPageGenerator$App.call(ManPageGenerator.java:166)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at picocli.codegen.docgen.manpage.ManPageGenerator.main(ManPageGenerator.java:239)
:ledger-export-tool:generateManpageAsciiDoc (Thread[Execution worker Thread 7,5,main]) completed. Took 0.159 secs.

The workaround was to move the annotation to the class itself (and supporting changes), but I actually preferred annotating a method and passing it @Mixin with all the options.

The fix (I believe) would be to add a way of specifying an annotated method to ManPageGenerator.

PS: You can see the changes I made to workaround here: ConsensusJ/WalletLedgerExport@22f4ba0#diff-f423761483c976760e2804c688f91600118acc272816cce90c6fe568ede763cd

msgilligan added a commit to ConsensusJ/WalletLedgerExport that referenced this issue Oct 24, 2022
This required us to move away from putting the @command annotation on
the export method, rename it to `call`, and annotate the class itself:

See: remkop/picocli#1858
@msgilligan msgilligan changed the title ManPageGenerator: Can't find annotated method class ManPageGenerator: Can't find annotated method Oct 24, 2022
@remkop remkop added type: bug 🐛 theme: codegen An issue or change related to the picocli-codegen module labels Oct 24, 2022
@remkop
Copy link
Owner

remkop commented Dec 16, 2022

I see, interesting! I only anticipated @Command-annotated methods that were subcommands of a @Command-annotated class, I did not anticipate your use case. 😅

Note that this is not limited to just ManPageGenerator, I think none of the tools currently support this use case where the class itself is not a command, but it has a @Command-annotated method that is invoked from the main method.

I won't have time to work on this, but if anyone offers to provide a pull request that implement this with some tests, I would be happy to review it.

@remkop remkop changed the title ManPageGenerator: Can't find annotated method Add support for @Command-annotated methods to codegen tools (was:ManPageGenerator: Can't find annotated method) Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help-wanted 🆘 theme: codegen An issue or change related to the picocli-codegen module type: enhancement ✨
Projects
None yet
Development

No branches or pull requests

2 participants