-
Notifications
You must be signed in to change notification settings - Fork 422
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 default value and custom converter for individual options/parameters #1308
Comments
Hi @asarkar, thanks for your feedback! Are you aware that the The user manual has a section Option-specific Type Converters but I realize now that this may be easily overlooked. Thanks for pointing that out! I will improve the user manual shortly. About default values, the Maybe interesting: the The other way to dynamically provide default values is to set a Is this useful? |
Hi @remkop
Obviously, the above can't be achieved by a simple string. To make things worse, the setter method is not called if the option is not specified by the user (null), so I end up calling it from |
Sorry I don’t follow. |
Then make the default value a special string (instead of null), so the type converter can have special logic for the “no value specified” case. |
Actually, thinking about it some more, you don’t need a custom type converter, the logic in the setter method is fine. All you need is to set a |
Just so that I’m clear, using the |
Yes, that is correct. 👍 I am always open to suggestions for improving the documentation. 🔧 |
Verified to be working using a default value |
@asarkar Good to hear you found something that works for you! Don't forget to leave picocli a ⭐ star on GitHub if you like the project. 😉 |
Please take a look at the updated section for Single Parameter Type Converters in the user manual. This should clarify the The section on default values already seems pretty clear to me:
For an annotated setter method, "assigned" cannot mean anything else than that the setter method is called. Not sure if this can be phrased better. Can you suggest any concrete improvements? |
The converter docs seem fine, I just couldn’t find it until you pointed it out. |
Hi @asarkar sorry for the late reply. I finally got around to updating the text for the Default Values section in the user manual. Thanks again for the feedback, and don't forget to leave picocli a star ⭐ on GitHub to help promote the project. 😉 |
…OTES" This reverts commit edb7e45.
…-NOTES" This reverts commit 7498040.
This reverts commit afec872.
…OTES" This reverts commit edb7e45.
…-NOTES" This reverts commit 7498040.
This reverts commit afec872.
Currently, the default value and custom converter can only be specified at the class level, which is not useful at all for the following reasons:
IDefaultValueProvider
returns aString
, not the actual field type.IDefaultValueProvider
to provide default values for multiple fields.Being able to provide a default value provider class and a converter class in the
Option
(andParameter
) annotation would be extremely useful. The default value provider may return a type that can be converted to the field type using the available converters (including the inline one).The text was updated successfully, but these errors were encountered: