Skip to content
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

Unmatched argument #1309

Closed
mininotallarines opened this issue Jan 19, 2021 · 5 comments
Closed

Unmatched argument #1309

mininotallarines opened this issue Jan 19, 2021 · 5 comments

Comments

@mininotallarines
Copy link

mininotallarines commented Jan 19, 2021

Issue

I was playing around with the subcommands and suddenly I got an unmatched argument exception but I think this might bug.

Running the following command test start sta or test restart rest tries to autocorrect the sta and/or rest to their subcommand.

The command never runs and it just says Did you mean: restart or start?

@Command(name = "test", mixinStandardHelpOptions = true)
public class TestCommand implements Callable<Integer> {

	@Override
	public Integer call() throws Exception { throw new ParameterException(spec.commandLine(), "Missing required subcommand"); }
	
	@Command(name = "start", description = "start", mixinStandardHelpOptions = true)
	public int start(
			@Parameters(index = "0", paramLabel = "id") String id) { return 0; }
	
	@Command(name = "restart", description = "restart", mixinStandardHelpOptions = true)
	public int restart(
			@Parameters(index = "0", paramLabel = "id") String id) { return 0; }
	
}

I'm running the command using the CommandLine object as follows:

new CommandLine(new TestCommand()).execute("restart", "rest")
new CommandLine(new TestCommand()).execute("start", "sta")

Environment

Operating System Windows 10
IDE Eclipse 2020-12 (4.18.0)
Picoclli Picocli version 4.6.1

@remkop remkop added status: duplicate 👨🏻‍🤝‍👨🏻 A duplicate of another issue and removed status: duplicate 👨🏻‍🤝‍👨🏻 A duplicate of another issue labels Jan 19, 2021
@remkop
Copy link
Owner

remkop commented Jan 19, 2021

Hi @mininotallarines, thank you for raising this!

I initially thought this might be related to #1125,
but looking closer, I believe there may be a problem with the test.

Instead of specifying "restart rest" as a single argument, can you try specifying "restart" and "rest" as separate arguments?

new CommandLine(new TestCommand(), "restart", "rest"); // ensure "restart" and "rest" are separate args
new CommandLine(new TestCommand(), "start", "sta") // ensure "start" and "sta" are separate args

@mininotallarines
Copy link
Author

Hi @mininotallarines, thank you for raising this!

I initially thought this might be related to #1125,
but looking closer, I believe there may be a problem with the test.

Instead of specifying "restart rest" as a single argument, can you try specifying "restart" and "rest" as separate arguments?

new CommandLine(new TestCommand(), "restart", "rest"); // ensure "restart" and "rest" are separate strings
new CommandLine(new TestCommand(), "start", "sta") // ensure "start" and "sta" are separate strings

I'm sorry, I'll change the post, that is a mistake on my part.. I am actually passing in an array so that would translate to separate arguments..

@remkop
Copy link
Owner

remkop commented Jan 19, 2021

I cannot reproduce the issue.
I created this test:

@Command(name = "test", mixinStandardHelpOptions = true)
class TestCommand implements Callable<Integer> {

    @Spec
    CommandSpec spec;

    public Integer call() throws Exception {
        throw new ParameterException(spec.commandLine(), "Missing required subcommand");
    }

    @Command(name = "start", description = "start", mixinStandardHelpOptions = true)
    public int start(
            @Parameters(index = "0", paramLabel = "id") String id) {
        System.out.printf("start was called with %s%n", id);
        return 111;
    }

    @Command(name = "restart", description = "restart", mixinStandardHelpOptions = true)
    public int restart(
            @Parameters(index = "0", paramLabel = "id") String id) {
        System.out.printf("restart was called with %s%n", id);
        return 222;
    }
}

@Test
public void testIssue1309() {
    assertEquals(222, new CommandLine(new TestCommand()).execute("restart", "rest"));
    assertEquals(111, new CommandLine(new TestCommand()).execute("start", "sta"));
}

This test passes and prints the following output:

restart was called with rest
start was called with sta

All seems to be working as expected... Can you try running this test?
If the issue still persists, can you point me to a public repo with an example that reproduces the issue?

remkop added a commit that referenced this issue Jan 19, 2021
@mininotallarines
Copy link
Author

I'm sorry, after 2 days I managed to find the issue in the command parser. So the command ran with what was apparently 1 argument 'rest' or 'sta'.. this is awkward :/

@remkop
Copy link
Owner

remkop commented Jan 19, 2021

No worries.
It's proof you are human. 🚫 👽 😄

Enjoy picocli!
(And please give picocli a ⭐ star on GitHub if you like the project. 😉 )

MarkoMackic pushed a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants