picocli
picocli copied to clipboard
ArgGroup for help and generic options
In the help output, we'd like to separate command-specific options from generic options like --help
, --version
, --log-level
, ... At the same time, we'd also like to avoid having to define an ArgGroup
in every individual command class to hold command-specific options; in many cases we can't even use ArgGroups
because they cannot contain Mixins
(#1793).
So, basically we'd like to put generic options in their own ArgGroup
to remove them from the usage.optionListHeading
section, such that we can exclusively use this section for command-specific options.
In our top-level command class, I now have the following code:
@Command(name = "fcli",
scope = ScopeType.INHERIT,
usageHelpAutoWidth = true,
sortOptions = false,
showAtFileInUsageHelp = false,
resourceBundle = "com.myapp.i18n.MyAppMessages",
versionProvider = MyVersionProvider.class,
subcommands = {
SubCommand1.class,
SubCommand2.class,
}
)
public class MyAppCommands {
@ArgGroup(exclusive = false, headingKey = "arggroup.loggingAndHelp.heading")
private LoggingAndHelpOptionsArgGroup loggingAndHelpOptionsArgGroup = new LoggingAndHelpOptionsArgGroup();
private static final class LoggingAndHelpOptionsArgGroup {
@Option(names = {"-V", "--version"}, versionHelp = true, description = "display version info", scope = ScopeType.INHERIT)
boolean versionInfoRequested;
@Option(names = {"-h", "--help"}, usageHelp = true, description = "display this help message", scope = ScopeType.INHERIT)
boolean usageHelpRequested;
@Option(names = "--log-level", scope = ScopeType.INHERIT)
private String logLevel;
}
}
Unfortunately, this doesn't achieve the desired result. On the top-level command, the logging and help options are correctly shown under arggroup.loggingAndHelp.heading
, but the ArgGroup
is not respected in subcommands (which is somewhat to be expected, as we're inheriting individual options rather than the ArgGroup
); these options again appear under usage.optionListHeading
.
Any chance we can have a scope = ScopeType.INHERIT
attribute on ArgGroup
, such that subcommands inherit the full ArgGroup
rather than individual options?