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
When CommandLine is initialized with IFactory all subcommands get created instead of only the one called #690
Comments
Sorry for my late response. I was running a marathon. :-) I need to think about this a bit. I'm open to this in principle, as long as it does not introduce too many complexities. |
No worries (besides that you will have to work on your marathon time ;) I dont know enough about the internals but it could be quite simple. Then the command line can be parsed without instantiating any objects. If I get some time I will have a look but I guess you can do that way faster ;D |
Not sure when I will be able to get to it, given the todo list for 4.0-beta and 4.0. If you have time to look at it that would be great. |
FYI: I have started to reduce the scope for picocli 4.0 in order to get something out before the end of the summer. I won't be able to get to this item until after that. |
@danielBreitlauch a first cut of lazily instantiated user objects has landed in master. Please try it out and let me know what you think. |
Thanks I will |
@danielBreitlauch Sorry, it looks like there is still more work to be done. |
@danielBreitlauch I believe it is all fixed now. |
@danielBreitlauch, All, picocli 4.2.0 has been released, including this fix. Enjoy! |
@remkop Hi, it looks like using the |
@Immueggpain What is the problem you are experiencing? Can you tell me how to reproduce it? What did you expect to see and what do you actually see? |
@Immueggpain Do you mean a command annotated with |
@remkop Sorry for the confusion. Here is the code:
help subcommand will trigger foo's constructor |
@Immueggpain Thanks for the clarification. The problem is not the presence of the @Command(name = "foo")
static class Foo {
public Foo() {
throw new IllegalStateException("Don't instantiate me!");
}
}
@Command(name = "playpico",
description = "play picocli", mixinStandardHelpOptions = true,
subcommands = { //CommandLine.HelpCommand.class,
Foo.class })
static class Launcher implements Runnable {
public static void main(String[] args) {
int exitCode = new CommandLine(new Launcher())
.setCaseInsensitiveEnumValuesAllowed(true)
.setUsageHelpLongOptionsMaxWidth(40)
.setUsageHelpAutoWidth(true)
.execute(args);
//System.exit(exitCode);
}
public void run() {
CommandLine.usage(this, System.out);
}
} This will produce the following stack trace:
When the usage help message is created, subcommands are instantiated in the I need to look at this further... |
@Immueggpain Thanks for raising this! I now believe this is a leftover from early work on this (#690) ticket that was not cleaned up. I will close this ticket; I created a new ticket (#968) for fixing the problem you identified; the fix will be in the next picocli release. |
I create a CommandLine with an IFactory containing a Guice injector.
The cli consists of a lot of subcommands that are heavy to initialize.
All of them injection quite some heavy client instances. So I was expecting that picocli is only creating objects of subcommands that are needed. Initializing all the unused, not called subcommands generates quite some start up overhead.
The text was updated successfully, but these errors were encountered: