Closed davsclaus closed 1 week ago
Example how to manually add default values
@CommandLine.Option(names = { "--sort" }, completionCandidates = NameTypeCompletionCandidates.class,
- description = "Sort by name or type", defaultValue = "name")
+ description = "Sort by name or type (default: ${DEFAULT-VALUE})", defaultValue = "name")
String sort;
@CommandLine.Option(names = { "--filter" },
- description = "Filter beans names (use all to include all beans)", defaultValue = "all")
+ description = "Filter beans names; use all to include all beans (default: ${DEFAULT-VALUE})", defaultValue = "all")
String filter;
@CommandLine.Option(names = { "--properties" },
- description = "Show bean properties", defaultValue = "true")
+ description = "Show bean properties (default: ${DEFAULT-VALUE})", defaultValue = "true")
boolean properties;
@CommandLine.Option(names = { "--nulls" },
- description = "Include null values", defaultValue = "true")
+ description = "Include null values (default: ${DEFAULT-VALUE})", defaultValue = "true")
boolean nulls;
@CommandLine.Option(names = { "--internal" },
- description = "Include internal Camel beans", defaultValue = "false")
+ description = "Include internal Camel beans (default: ${DEFAULT-VALUE})", defaultValue = "false")
boolean internal;
@CommandLine.Option(names = { "--dsl" },
- description = "Include only beans from YAML or XML DSL", defaultValue = "false")
+ description = "Include only beans from YAML or XML DSL (default: ${DEFAULT-VALUE})", defaultValue = "false")
boolean dsl;
Hi @davsclaus picocli has that feature, see https://picocli.info/#_legacy_configuration_for_displaying_default_values
Use @Command(showDefaultValues = true)
o append the default value of all non-null options and positional parameters to the description column.
To change the layout of the help, and add an extra column, please see the picocli-examples subproject on github.
@remkop thank you very much for the help. This is what I needed.
We use picocli at the Apache Camel project for our CLI. We have about 50 commands, each with a mixed set of options. https://camel.apache.org/manual/camel-jbang.html
The
--help
output shows the options and their description. However what we struggle with is that the default values is not possible to see / know. To include default values you would have to update every description to include it via a special literal text(default: ${DEFAULT-VALUE})
.Before
After (with default values) where I have manually updated all the descriptions for evert option in this command.
Now the default values are shown in the description.
1) I wonder if there can be added some way to automatic include this via some new option in the
@Command
Or some other way to enable this globally for all commands.
2) I would also like to see the dumped
--help
to show the default values more prominently in a separate column instead of in the description. This makes it much quicker to see the defaults instead of scanning all the description texts.