Skip to content

Conversation

@MarkoMackic
Copy link
Contributor

Proposes API for #1259

@codecov-io
Copy link

codecov-io commented Nov 27, 2020

Codecov Report

Merging #1266 (a126fa1) into master (abb4559) will increase coverage by 0.00%.
The diff coverage is 95.00%.

Impacted file tree graph

@@            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           
Impacted Files Coverage Δ Complexity Δ
src/main/java/picocli/CommandLine.java 93.65% <95.00%> (+<0.01%) 323.00 <7.00> (+6.00)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update abb4559...a126fa1. Read the comment docs.

Copy link
Owner

@remkop remkop left a 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.)

@MarkoMackic
Copy link
Contributor Author

Let's do a more generic one :)

@MarkoMackic
Copy link
Contributor Author

@remkop What do you think about this approach ?

@MarkoMackic
Copy link
Contributor Author

There is one test failing :) I'll fix that

Copy link
Owner

@remkop remkop left a 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!

@MarkoMackic
Copy link
Contributor Author

MarkoMackic commented Nov 28, 2020

@remkop I'll fix the codestyle. We could call it modelPreprocessor. That name empasizes it's done at model build time.

@remkop
Copy link
Owner

remkop commented Nov 28, 2020

IModelTransformer?

@MarkoMackic
Copy link
Contributor Author

That makes sense. I'll refactor tomorrow evening.

@MarkoMackic
Copy link
Contributor Author

@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.

@MarkoMackic
Copy link
Contributor Author

And also PR title should be changed, because the functionality impact is wider, but I don't have good words to define it

@remkop remkop changed the title Model build time subcommands filtering Support user-defined model transformations after initialization and before parsing Nov 30, 2020
@MarkoMackic
Copy link
Contributor Author

MarkoMackic commented Nov 30, 2020

@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 void(CommandSpec) and it could remain final )

@MarkoMackic MarkoMackic force-pushed the features/model-build-time-subcommands-filtering branch from 5437bc8 to b53d510 Compare November 30, 2020 21:58
@MarkoMackic MarkoMackic force-pushed the features/model-build-time-subcommands-filtering branch from b53d510 to af4c1f9 Compare December 1, 2020 07:15
Copy link
Owner

@remkop remkop left a 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;
Copy link
Owner

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; }

Copy link
Contributor Author

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.

Copy link
Contributor Author

@MarkoMackic MarkoMackic Dec 1, 2020

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done it.

@MarkoMackic
Copy link
Contributor Author

MarkoMackic commented Dec 1, 2020

@remkop This is going with 4.6 ? I'll handle requested changes today, and write some docs

@MarkoMackic MarkoMackic force-pushed the features/model-build-time-subcommands-filtering branch from af82e22 to 3f93fda Compare December 1, 2020 11:03
@MarkoMackic
Copy link
Contributor Author

MarkoMackic commented Dec 1, 2020

@remkop Could you please write the docs ? You have a wider understanding of CommandSpec API. I could only write about filtering subcommands :)

Copy link
Owner

@remkop remkop left a 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.

@MarkoMackic
Copy link
Contributor Author

@remkop All good :) Please make one final review, add this to user manual and we're ready to go.

Copy link
Owner

@remkop remkop left a 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 remkop linked an issue Dec 2, 2020 that may be closed by this pull request
@MarkoMackic
Copy link
Contributor Author

@remkop When is 4.6 going to be released ?

@remkop
Copy link
Owner

remkop commented Dec 9, 2020

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.

@remkop remkop merged commit 0cd5d8d into remkop:master Dec 14, 2020
remkop added a commit that referenced this pull request Dec 14, 2020
remkop added a commit that referenced this pull request Dec 14, 2020
@remkop
Copy link
Owner

remkop commented Dec 14, 2020

Merged and added documentation.
Feedback welcome!

remkop added a commit that referenced this pull request Dec 14, 2020
MarkoMackic pushed a commit to MarkoMackic/picocli that referenced this pull request Oct 17, 2021
MarkoMackic pushed a commit to MarkoMackic/picocli that referenced this pull request Oct 17, 2021
MarkoMackic pushed a commit to MarkoMackic/picocli that referenced this pull request Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this pull request Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this pull request Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this pull request Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this pull request Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this pull request Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this pull request Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider providing API for modifying the model at initialization

3 participants