-
Notifications
You must be signed in to change notification settings - Fork 424
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
Argument groups: default value is disregarded #746
Labels
Milestone
Comments
This looks like a bug. Thank you for raising this! |
remkop
added a commit
that referenced
this issue
Jun 24, 2019
Thanks again for raising this; this clarified the semantics for default values in argument groups quite a bit. I made some improvements, but it may not behave the way you expect in your example use case (because your example has a static field). Picocli will assign default values in the following cases:
To demonstrate: @Command(name = "ArgGroupsTest")
static class CommandWithDefaultValue {
@ArgGroup(exclusive = false)
InitializedGroup initializedGroup = new InitializedGroup();
@ArgGroup(exclusive = false)
DeclaredGroup declaredGroup;
static class InitializedGroup {
@Option(names = "-staticX", arity = "0..1", defaultValue = "999", fallbackValue = "-88" )
static int staticX;
@Option(names = "-instanceX", arity = "0..1", defaultValue = "999", fallbackValue = "-88" )
int instanceX;
}
static class DeclaredGroup {
@Option(names = "-staticY", arity = "0..1", defaultValue = "999", fallbackValue = "-88" )
static Integer staticY;
@Option(names = "-instanceY", arity = "0..1", defaultValue = "999", fallbackValue = "-88" )
Integer instanceY;
}
}
@Test
public void test746DefaultValue() {
//TestUtil.setTraceLevel("DEBUG");
CommandWithDefaultValue bean = new CommandWithDefaultValue();
CommandLine cmd = new CommandLine(bean);
cmd.parseArgs();
assertEquals(999, bean.initializedGroup.instanceX);
assertEquals(999, CommandWithDefaultValue.InitializedGroup.staticX);
assertNull(bean.declaredGroup);
assertNull(CommandWithDefaultValue.DeclaredGroup.staticY);
} |
remkop
added a commit
that referenced
this issue
Jun 25, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm running the code below (assertions enabled):
Since
x = 0
, I'm getting:Is this the intended behaviour?
The text was updated successfully, but these errors were encountered: