-
Notifications
You must be signed in to change notification settings - Fork 445
Support user-defined model transformations after initialization and before parsing #1266
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 user-defined model transformations after initialization and before parsing #1266
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1266 +/- ##
=========================================
Coverage 93.82% 93.82%
- Complexity 461 467 +6
=========================================
Files 2 2
Lines 6851 6869 +18
Branches 1842 1845 +3
=========================================
+ Hits 6428 6445 +17
- Misses 138 139 +1
Partials 285 285
Continue to review full report at Codecov.
|
remkop
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a functionality perspective, this proposal seems too limited:
all that any preprocessor can do is prevent a subcommand from being added.
What if there are applications that want to dynamically add a subcommand, or add an option, or remove a subcommand from the parent and add it to a different subcommand, or make any other change to the model?
From a design perspective, I prefer interfaces to classes, and ideally an interface with just a single abstract method (to allow the use of lambdas and Groovy closures in various scenarios.)
|
Let's do a more generic one :) |
|
@remkop What do you think about this approach ? |
|
There is one test failing :) I'll fix that |
remkop
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the update, I like the new interface signature very much.
I had some feedback, can you take a look?
On a separate note, I am starting to think perhaps there is a better name than "preprocessor"...
I don't have any ideas yet, open to suggestions.
I am not sure if the name should emphasize the timing, the fact that this is something that is applied between constructing the model and using the model to parse command line args. Or whether the name should emphasize that this is something that allows applications to modify/transform the model.
Still thinking, suggestions welcome!
|
@remkop I'll fix the codestyle. We could call it |
|
|
|
That makes sense. I'll refactor tomorrow evening. |
|
@remkop Please replace the X.X in this branch with the release this is going to get into. And read the comment about this after build transformation. |
|
And also PR title should be changed, because the functionality impact is wider, but I don't have good words to define it |
|
@remkop Please review, CommandSpec is not final anymore because it's replaced by preprocessors/transformers. This would allow preprocessor/transformer to return totally new command spec ( maybe you want only to have methods implemented in CommandSpec that are able to modify it, than interface signature would be |
5437bc8 to
b53d510
Compare
b53d510 to
af4c1f9
Compare
remkop
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
I think we are getting close.
I added some feedback for minor adjustments, can you take a look?
We should also mention this feature in the user manual (index.adoc).
Perhaps add a small section called Model Transformations, between @spec annotation and [Custom Factory].(https://picocli.info/#_custom_factory). If you can provide an initial draft, perhaps with a usage example, then I take care of the rest.
| private Integer exitCodeOnInvalidInput; | ||
| private Integer exitCodeOnExecutionException; | ||
|
|
||
| private IModelTransformer modelTransformer = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add public getter and setter accessors for this attribute to CommandSpec?
Following the naming convention I use here, that would be
/** Some javadoc here
* @since 4.6 */
public IModelTransformer modelTransformer() { return modelTransformer; }
/** Some javadoc here
* @since 4.6 */
public CommandSpec modelTransformer(IModelTransformer modelTransformer) { this.modelTransformer = modelTransformer; return this; }There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's ok, than we need to add public API to CommandLine to manually trigger the transformation ? I'll see into this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@remkop Actually you don't need programmatic API for this :) because you're constructing/editing command line/model on the fly ( i.e. your code does construction ) , but maybe it can serve some purpose. I've left a single test empty to cover this functionality, you could probably write that usecase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done it.
|
@remkop This is going with 4.6 ? I'll handle requested changes today, and write some docs |
af82e22 to
3f93fda
Compare
|
@remkop Could you please write the docs ? You have a wider understanding of |
remkop
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, thank you very much!
I added some minor feedback, would be nice if you can take care of them, if not, I can do it.
I will update the user manual, no worries.
|
@remkop All good :) Please make one final review, add this to user manual and we're ready to go. |
remkop
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, many thanks!
|
@remkop When is 4.6 going to be released ? |
|
I am taking next week off from work. That is when I am planning to merge approved PRs and complete other outstanding work for 4.6 and do the release. |
|
Merged and added documentation. |
This reverts commit 2d64988.
This reverts commit b93e0d6.
This reverts commit bbb8e5e.
This reverts commit 2d64988.
This reverts commit b93e0d6.
This reverts commit bbb8e5e.
Proposes API for #1259