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

Support annotating methods with @Option and @Parameters #182

Closed
remkop opened this issue Sep 12, 2017 · 1 comment
Closed

Support annotating methods with @Option and @Parameters #182

remkop opened this issue Sep 12, 2017 · 1 comment

Comments

@remkop
Copy link
Owner

remkop commented Sep 12, 2017

No description provided.

@remkop remkop added this to the 2.1.0 milestone Oct 20, 2017
@remkop remkop modified the milestones: 2.1.0, 2.2.0 Nov 1, 2017
@remkop remkop modified the milestones: 2.2.0, 2.1.0 Nov 11, 2017
@remkop remkop modified the milestones: 2.1.0, 2.2.0 Nov 28, 2017
@remkop remkop mentioned this issue Dec 7, 2017
@remkop remkop changed the title Add support for @Option and @Parameters annotations on setter methods Method annotation @Option and @Parameters support Dec 19, 2017
@remkop remkop changed the title Method annotation @Option and @Parameters support Support annotating methods with @Option and @Parameters Feb 14, 2018
@remkop
Copy link
Owner Author

remkop commented Apr 11, 2018

Summary of implementing this in Groovy's upcoming picocli-based groovy.util.CliBuilder (#258):

Getter methods can be annotated with @Option:

  • for interfaces (where the implementation is a picocli-backed java.util.Proxy)
  • for methods that return a mutable data structure like a Collection or a Map

Here the IGetter binding gets the initial value from the getter method and keeps a reference to it. This reference is shared with the ISetter binding so the reference is replaced if picocli calls ArgSpec.setValue.

Setter methods must be annotated for implementation classes

  • for single-value options or array values
  • either getter or setter methods may be annotated for collection or map options

If picocli asks ArgSpec.getValue before the setter has been called, the initial value is either null or an empty collection or map. The parsed (or default) value is then set via the ISetter which invokes the setter method and keeps a reference to the value. This reference is shared with the IGetter so that the updated value is returned with ArgSpec.getValue is called after the setter has been called.

@remkop remkop modified the milestones: 3.0, 3.1 Apr 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant