-
|
Hello, I am trying to improve the output of I can see the various annotations let me do that but I'd prefer adding this in code rather as large piece of text within the annotation itself. For version I can implement Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Yes! Picocli has a rich programmatic model for exactly this. The key class is Adding header/description/footer programmatically after construction: CommandLine cmd = new CommandLine(new MyCommand());
cmd.getCommandSpec().usageMessage()
.header("My Command - does amazing things%n",
"See https://example.com/docs for full documentation%n")
.description("A longer description here.%n",
"Supports multiple lines.%n")
.footer("%nExamples:%n my-command --option value%n");If you want to set this inside the command class itself (useful for dynamic content), inject the spec via a @Command(name = "my-command")
class MyCommand implements Runnable {
@Spec
void setSpec(CommandSpec spec) {
spec.usageMessage()
.header(loadHeaderFromFile()) // dynamic content!
.description(buildDescription());
}
private String[] loadHeaderFromFile() { /* ... */ }
}The full This is essentially the programmatic equivalent of the annotation attributes, with the advantage that you can compute values at runtime. Hope this helps! Let me know if you need clarification. |
Beta Was this translation helpful? Give feedback.
Yes! Picocli has a rich programmatic model for exactly this. The key class is
CommandSpec, which you can access via the@Specannotation, andUsageMessageSpecwhich controls the help output.Adding header/description/footer programmatically after construction:
If you want to set this inside the command class itself (useful for dynami…