-
Notifications
You must be signed in to change notification settings - Fork 421
-
Notifications
You must be signed in to change notification settings - Fork 421
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
behavior of defaultValue #962
Comments
Can you please show how to reproduce this problem? |
Of course, the code is below: import picocli.CommandLine;
@CommandLine.Command(name = "run")
public class App implements Runnable {
@CommandLine.Option(names = "--port", defaultValue = "${env:PORT}", required = true)
Integer PORT;
static public void main(String[] args) {
App app = new App();
args = new String[]{"--port", "5672"};
CommandLine cmd = new CommandLine(app);
cmd.execute(args);
}
public void run() {
System.out.println(PORT);
}
} before run : export PORT="xxx" |
then may below information in stderr:
|
@sjyMystery Thank you for the clarification. I understand the issue now. Please read my comment on that ticket for more details. Are you interested in providing a pull request for this? That would be great! |
@remkop I've get your point.By the way, is there anything need or suggested to read before I make a pr?Thanks. |
@sjyMystery There is no documentation on the implementation, just the source code. :-) It may be as simple as reordering these 2 lines in Before: private void parse(List<CommandLine> parsedCommands, Stack<String> argumentStack, String[] originalArgs, List<Object> nowProcessing) {
...
try {
applyDefaultValues(required); // currently defaults are applied first
processArguments(parsedCommands, argumentStack, required, initialized, originalArgs, nowProcessing);
} catch (InitializationException ex) {
... After: private void parse(List<CommandLine> parsedCommands, Stack<String> argumentStack, String[] originalArgs, List<Object> nowProcessing) {
...
try {
processArguments(parsedCommands, argumentStack, required, initialized, originalArgs, nowProcessing);
applyDefaultValues(required, initialized); // only apply defaults to the missing args
} catch (InitializationException ex) {
... Then, in But let's add some tests to verify. |
@sjyMystery Have you had a chance to look at this? Let me know if you get stuck anywhere, I will try to help. :-) |
Fixed in master. To verify this, check out picocli master locally, and build it with
You can then try this in a project that uses the |
Hi, guys:
There's an unexpected behavior of the
defaultValue
param in@Option
Annotation.When use default values from environment variables of invalid types, it always throws ParameterException even though I passed the value of the argument.
How to solve it
Maybe we can disable the type-checking of default value when the argument value has been already passed.
And I will be honored to submit the example code of this situation and create a pull request if necessary.
The text was updated successfully, but these errors were encountered: