jcommander
jcommander copied to clipboard
FR: guice injection support
In the past I've used flag binding systems that are very well integrated with the dependency injection system we've used, specifically guice. Particularly usages like the following are very helpful:
class MyFlagModule extends ParameterModule {
@Parameter(names = {"--port"}, bindingAnnotation = ThePort.class)
private Integer port = 0;
}
class MyServer {
@Inject
MyServer(@ThePort Integer port) {}
}
This would allow declaring parameters in a new class ParameterModule (described below) to automatically bind parameters declared with a new bindingAnnotation
member of the Parameter class. See here for more on Guice binding annotations.
In this case the ParameterModule
class could be an abstract class that extends guice.inject.AbstractModule, perhaps located in new package com.beust.jcommander.guice.ParameterModule
. The #configure
method of ParameterModule would iterate over all parameters in the class with a binding annotation and automatically bind the value.
Any interest? I could take a crack at an implementation if there is some.
@erickj If this is still an issue for you, take a look at https://picocli.info/#_dependency_injection