Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I extracted ParserUtil.createInstance into a Factory interface. This is configurable using the builder. The default Implementation is using the logic from the old createInstance method in ParserUtil. This way, the change is fully backwards compatible but allows users to implement and provide their own factory implementation. This enables them to use Guice or Spring DI containers to instatiate their commands. In Short: I added dependency injection support. An example Factory for Google Guice Support would look like this:
An example cli main class would look like this:
The next step would be to provide The Factory Implementations for the various di frameworks but that would mean adding dependencies to those frameworks which will be inherited by any projects using this library. A better approach would be to convert this project to a maven multi module project and add one module for each Factory. Third option would be to update the documentation and leave the Factory implementation up to the user. Which is your preferred option?