-
Notifications
You must be signed in to change notification settings - Fork 433
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
Allow user to overwrite Collection field default value #216
Comments
Yes, that makes sense. It will require some work to keep track of the original default values so we only replace the original collection with a new collection when the first user-specified option is matched, and for subsequent options add to (and don't replace) the new collection. |
true, that was an oversight I had in the temporary "fix" I incorporated in my fork. Any idea, how to achieve this? Maybe introduce a boolean flag for each option, whether the current field value is user-specified? |
If you want to create a pull request, perhaps add a Otherwise (without modifying the code), the workaround is similar to #213: keep the default value Note that this use case (a collection or array with multiple default values) is not covered nicely by JCommander's |
[#216] Parsed values are no longer appended to, but instead replace, the default value of multi-value (array, Collection or Map) options and positional parameters. Thanks to [wiwie](https://github.com/wiwie) for the request. [#261] Options and positional parameters with a `defaultValue` are never required. Thanks to [ymenager](https://github.com/ymenager) for the request. [#315] Initialize ArgSpec value with `defaultValue` before parsing command line. Closes 216 Closes 261 Closes 315
Implemented: parsed values are no longer appended to, but instead replace, the default value of multi-value (array, Collection or Map) options and positional parameters. |
Right now, if an option field is a Collection and is initialized with a default value in the code, and at the same time the user code is invoked with parameters for that collection field, these parameters are appended to the existing collection.
However, in my eyes it would make more sense to reinitialize the field with a new collection only containing the user-passed parameters. This is at least, what I expected.
Right now, there is no way of me saying "use only the parameters I passed in, and forget about the default one".
The text was updated successfully, but these errors were encountered: