-
Notifications
You must be signed in to change notification settings - Fork 426
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
boolean field option is true if option is present but boolean method parameter option is false if option is present #1772
Comments
It seems also that no matter what value I specify for -s option (after adding arity="1"), the value is always false.
Command: |
I tested both variants you mentioned but I am unable to reproduce the issue. I get:
Can you try with |
I don't have anymore the previous minimal example but I've created a minimal project where you can reproduce the issue with a test:
|
@Onedy Thank you for the test project to reproduce the issue. package test;
import org.junit.jupiter.api.Test;
import picocli.CommandLine;
import picocli.CommandLine.*;
import static org.junit.jupiter.api.Assertions.*;
import static picocli.CommandLine.ScopeType.INHERIT;
/**
* https://github.com/remkop/picocli/issues/1772
*/
public class Issue1772 {
public CommandLine getTestCommandLine(ParentTestCommand parentCommand, TestCommand testCommand, IFactory factory) {
CommandLine commandLine = new CommandLine(parentCommand, factory);
commandLine.addSubcommand(testCommand);
return commandLine;
}
@Command(name = "parentTestCommand", mixinStandardHelpOptions = true, scope = INHERIT)
static class ParentTestCommand {
}
@Command(name = "test")
static class TestCommand {
@Option(names = "-r")
public boolean option1;
public static String testString;
@Command(name = "subcommand")
void start(@Option(names = "-s") boolean option2) {
testString = "------> -r is " + option1 + " and -s is " + option2 + " <------";
}
}
@Test
public void testIssue1772() {
CommandLine commandLine = getTestCommandLine(new ParentTestCommand(), new TestCommand(), CommandLine.defaultFactory());
commandLine.execute("test", "-r", "subcommand", "-s");
assertEquals("------> -r is true and -s is true <------", TestCommand.testString);
}
} The above test fails with picocli 4.6.3, as demonstrated when I add it to the test project you provided:
But when I run the same test with the current version of picocli in the So, I believe this ticket can also be closed: since it won't be a problem after the fix for #1741 is released in the next version of picocli. |
Minimal example:
Command:
test -r subcommand -s
Output:
-r is true and -s is false
The text was updated successfully, but these errors were encountered: