-
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
Arguments and options are not passed in correct order to method subcommands #1774
Comments
The first case may be related to #1741, but the second case may be not. |
Thank you for the project to reproduce the problem. 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/1774
*/
public class Issue1774 {
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 = "parentTestCommand", mixinStandardHelpOptions = true, scope = INHERIT,
subcommands = TestCommand.class)
static class ParentTestCommand2 {
}
@Command(name = "test")
class TestCommand {
@Command(name = "subcommand")
void start(@Option(names = "-r", arity = "0") boolean optionR,
@Option(names = "-s", arity = "0") boolean optionS,
@Parameters(arity = "1") String url) {
System.out.println("Everything OK");
}
}
@Test
void testIssue1774() {
CommandLine commandLine = getTestCommandLine(new ParentTestCommand(), new TestCommand(), CommandLine.defaultFactory());
assertEquals(0, commandLine.execute("test", "subcommand", "-r", "-s", "URL"));
}
} This test fails with picocli 4.6.3, as demonstrated when I add it to the PicocliTest.zip project you provided:
However, the test succeeds when I run it with the latest main. |
I have a method subcommand in a class subcommand which is added to the main command by commandLine.addSubcommand().
This is my method:
and the command:
"test", "subcommand", "-r", "-s", "URL"
The issue is that arguments are passed in wrong order:
string, boolean, boolean
Minimal working example:
PicocliTest.zip
Just unzip and run with ./gradlew clean assemble :test --tests "test.MyTest" --info
And look at: java.lang.IllegalArgumentException: argument type mismatch
As you can see, the parsed args are passed in wrong order:
In the other hand, if I define the method as follows (with only one option):
and I execute the command:
"test", "subcommand", "-r", "URL"
the method is called with
boolean, boolean
instead ofboolean, String
The text was updated successfully, but these errors were encountered: