-
Notifications
You must be signed in to change notification settings - Fork 420
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
Support @Command(scope=INHERIT) (was: mixinStandardHelpOptions versus CommandLine.ScopeType.INHERIT) #1164
Comments
Hi @rnc, I can see how this would be useful. I also use the same version provider, as well as the I don't want to change the semantics of One alternative idea to solve this is to add programmatic API that applies these settings to the top-level command and all subcommands recursively, similar to That said, there are already two ways to deal with this with a limited amount of code repetition:
The last method (using a mixin) has the advantage that it allows other superclasses to inherit from, and it also works with For example: @Command(mixinStandardHelpOptions = true, versionProvider = CommonVersionProvider.class)
public class CommonStuffMixin {
}
@Command(name = "myapp")
public class TopLevelCommand {
@Mixin CommonStuffMixin common;
@Option(names = "-x")
int x;
@Command(subcommands = SubSubCommand.class)
void subcommand(@Mixin CommonStuffMixin common2) {
}
public static void main(String[] args) {
new CommandLine(new TopLevelCommand()).execute(args);
}
}
@Command(name = "subsub")
public class SubSubCommand {
@Mixin
CommonStuffMixin common;
@Option(names = "-y")
int y;
}
public class CommonVersionProvider implements IVersionProvider {
@Override
public String[] getVersion() {
return new String[] { "MyApp 1.2.3" };
}
} This installs the Thoughts? |
Hi! I completely agree that changing the semantics of I like the idea of e.g. CommandLine.setInherit (enum { mixinStandardHelpOptions | versionProvider | both } ) ( for instance). I am aware of the Mixin (or superclass) ... but was trying to avoid that given the really nice INHERIT option you added. Currently I just did which seems to do the equivalent without having to add the help command explicitly (via anotation/mixin/superclass) to all subclasses. |
Thinking about this some more, I can see how it would be useful to introduce a @Command(name = "bacon",
scope = INHERIT, // copy all attributes defined here to subcommands and sub-subcommands
description = "Bacon CLI",
mixinStandardHelpOptions = true,
versionProvider = VersionProvider.class,
subcommands = { Da.class, Pig.class, Pnc.class })
public class App { ... } This would copy all attributes ( Subcommands can override attributes by specifying their own values in the @Command(name = "da", description = "Dependency Analysis related commands", subcommands = { Da.Lookup.class })
public class Da { ... } The advantage of doing this declaratively in the annotations, instead of programmatically via This is a nice extension of #649. |
@remkop That sounds really neat! It would reduce boiler-plate code and make even nicer to work with :-) |
I pushed a commit to master that adds support for this, with some tests. |
Added documentation. CC @garretwilson you may like this extension of #649. |
According to https://picocli.info/#_help_options I can add
mixinStandardHelpOptions = true
which replaces the individualHowever if for the latter I have configured
CommandLine.ScopeType.INHERIT
then the help command is added to every subcommand as I understand. But it seems that adding it via themixinStandardHelpOptions = true
it is not inherited. Would it be possible to consider enabling inheritance forand possibly
Thanks.
The text was updated successfully, but these errors were encountered: