-
Notifications
You must be signed in to change notification settings - Fork 418
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
Method arg values not iterated correctly in CommandSpec#commandMethodParamValues #1741
Comments
Hi @Onedy, thank you for raising this. I had to guess and this is the test code I ended up with: // in some JUnit test class
@Command(name = "app", mixinStandardHelpOptions = true, scope = INHERIT, subcommands = Sorteo.class)
static class TestIssue1741 implements Runnable {
@Override public void run() {
System.out.println("Executing top-level command");
}
}
@Command(name = "sorteo")
static class Sorteo implements Runnable {
@Command(name = "enter")
void enter(@Parameters(arity = "1") String sentenceType,
@Parameters(arity = "1") String tweetUrl) {
System.out.printf("Subcmd 'enter' was called with %s and %s%n", sentenceType, tweetUrl);
}
@Override public void run() {
System.out.println("Executing command 'sorteo'");
}
}
@Test
public void testIssue1741() {
new CommandLine(new TestIssue1741()).execute("sorteo", "enter", "compound");
}
@Test
public void testIssue1741b() {
new CommandLine(new TestIssue1741()).execute("sorteo", "enter", "sentenceType1", "tweetURL2");
} When I run
When I run
Can you help massage this test into something that demonstrates the issue? |
I think the issue appears when the Spring factory is used. Here you have a minimal test: import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import picocli.CommandLine;
import java.util.List;
import static picocli.CommandLine.ScopeType.INHERIT;
@Configuration
class Config {
@Bean
public CommandLine getTestCommandLine(ParentCommand parentCommand, TestCommand testCommand, CommandLine.IFactory factory) {
CommandLine commandLine = new CommandLine(parentCommand, factory);
commandLine.addSubcommand(testCommand);
return commandLine;
}
}
@Component
@CommandLine.Command(name = "parentTestCommand", mixinStandardHelpOptions = true, scope = INHERIT)
class ParentTestCommand {
}
@Component
@CommandLine.Command(name = "sorteotest")
class TestCommand {
@CommandLine.Command(name = "entertest", description = "Start participating in a giveaway")
void enter(@CommandLine.Parameters(arity = "1") String sentenceType,
@CommandLine.Parameters(arity = "1") String tweetUrl) {
System.out.println("entering giveaway");
}
}
@SpringBootTest
class MyTest {
@Autowired
@Qualifier("getTestCommandLine")
private CommandLine commandLine;
@org.junit.jupiter.api.Test
void testIssue1741() {
commandLine.execute("sorteotest", "entertest", "sequenceType", "url");
}
} |
Hi @remkop, were you able to reproduce this issue? |
Hi @Onedy, no I haven't... Can you provide an example that doesn't use Spring, or alternatively an example that I can copy into the |
Hi @remkop, I couldn't build the Just unzip and run with
|
@Onedy Great thank you! |
I found the cause: |
I fixed the bug in the main branch and the fix will be included in the next release. |
Thank you for the fix! |
Hi,
I am getting an
IllegalArgumentException: argument type mismatch
when I input this command:sorteo enter compound tweeturl
Where
sorteo
andenter
are nested subcommands that inheritmixinStandardHelpOptions = true
from a parent command annotated with:and
compound
andtweeturl
are parameters. The issue is that these two parameters are retrieved as booleans when they are defined as String:This is happening because when the call stack gets to
![Captura de pantalla 2022-07-13 a las 23 01 01](https://user-images.githubusercontent.com/12222433/178834296-a2c0e292-913f-4be9-af80-c56332e5e9a4.png)
![Captura de pantalla 2022-07-13 a las 22 59 56](https://user-images.githubusercontent.com/12222433/178838297-4f8c978f-0302-4458-87de-d0d976e3f7cf.png)
commandMethodParamValues
the line
makes this line from the else
to retrieve the values of the mixinStandardHelpOptions insetead of the actual parameters, because
![Captura de pantalla 2022-07-13 a las 23 00 46](https://user-images.githubusercontent.com/12222433/178838498-c0aa45b5-fbfe-44f8-8272-bcc8d937cdac.png)
![Captura de pantalla 2022-07-13 a las 23 58 12](https://user-images.githubusercontent.com/12222433/178843828-509c7ebc-60a5-497d-951d-9b7ae4ed780c.png)
argIndex
starts at 2 as you can see in the variables pane:Am I doing something wrong?
The text was updated successfully, but these errors were encountered: