-
Notifications
You must be signed in to change notification settings - Fork 425
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
Picocli overwriting a value set in a constructor with no default value set and no option given on cli #2232
Comments
Can you please run that again with picocli tracing switched on, and paste the output here? Thank you! Either with system property
|
Please see output below:
|
Thank you; I'll have to look with the debugger to see what's happening. |
I took a quick look at the code and found the following lines, which seem to always default Optional to empty, even if the
If I'm interpreting this code correctly, this behavior looks intentional. Is it necessary for some reason for Optional values to not respect the lack of default? |
For some reason, the defaultvalue comes up as |
In the debugger, I see that the defaultvalue obtained from For args that are not I was probably assuming that many applications would not specify an initial value, and was thinking that FYI, looking at the user manual, section 4.6 Optional does mention this behaviour:
The current behaviour is following the documentation, but it is a bit inconsistent to have the initial value not work as the default value for To be honest, I am not sure how to proceed. |
I think your assumption that Is it possible to set it If you did that, then the common case of Optional defaulting to Then, you could update the docs to say the following
Another idea is to only set it to |
Yes. Makes sense. Looking into it. |
Fixed now in the main branch. Thank you for raising this! |
Thank you for the investigation and the quick fix! Will this be in the next release? |
This commit adds a source snapshot of picocli which fixes the following issue, which is required for Perf's use case. remkop/picocli#2232 After the next release of Picocli (time TBD), we can remove this source snapshot and include picocli using gradle.
Consider the following MWE:
The picocli documentation claims that
defaultValue
has a default value of"__no_default_value__"
, which I am interpreting to imply that it will not change the value of any field if there is no flag given on the command line.Thus, when I invoke this program with no arguments, I expect the following output:
However, the actual output I get is:
It appears that the
parseArguments
call has setarchive
toOptional.empty
despite the lack of arguments given on the command line and the lack of explicit setting for the default value of this option.Two questions about this:
The text was updated successfully, but these errors were encountered: