Skip to content
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

picocli.AutoComplete should allow specifying the IFactory implementation #585

Closed
bobtiernay-okta opened this issue Jan 2, 2019 · 5 comments
Labels
theme: auto-completion An issue or change related to auto-completion type: enhancement ✨
Milestone

Comments

@bobtiernay-okta
Copy link
Contributor

Currently it isn't possible to create @Command objects without a no-arg constructor since picocli.AutoComplete is hardcoded to use the default IFactory implementation. This means it isn't possible to use constructor injection to set dependencies as final fields.

Possibilities include specifying the IFactory class name as an argument to the tool or using the Java service loader mechanism.

@remkop remkop added this to the 3.9 milestone Jan 2, 2019
@remkop remkop added theme: auto-completion An issue or change related to auto-completion type: enhancement ✨ labels Jan 2, 2019
@remkop remkop closed this as completed in 5a5f89e Jan 3, 2019
@remkop
Copy link
Owner

remkop commented Jan 3, 2019

I pushed a change that implements this request to master.
This is the new option:

"  -c, --factory=<factoryClass>%n" +
"                             Optionally specify the fully qualified class name of%n" +
"                               the custom factory to use to instantiate the command%n" +
"                               class. When omitted, the default picocli factory is%n" +
"                               used.%n" +

Can you verify?

@bobtiernay-okta
Copy link
Contributor Author

Sure thing. Is it possible to do this via a build artifact or would I need to do this locally?

@remkop
Copy link
Owner

remkop commented Jan 3, 2019

The Travis continuous integration build jars are not published I think. You’ll probably need to build locally.

@bobtiernay-okta
Copy link
Contributor Author

Confirmed this worked:

java -cp picocli-3.9.0-SNAPSHOT.jar:uber.jar picocli.AutoComplete -c runtime.Factory commands.Commands

Might want to add a comment in the docs at some point that the factory itself needs to have a no-arg constructor.

Thanks for your help here!

@remkop
Copy link
Owner

remkop commented Jan 3, 2019

Good idea. Thanks for the confirmation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: auto-completion An issue or change related to auto-completion type: enhancement ✨
Projects
None yet
Development

No branches or pull requests

2 participants