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

Improve error message for unmatched arguments #733

Closed
remkop opened this issue Jun 18, 2019 · 0 comments
Closed

Improve error message for unmatched arguments #733

remkop opened this issue Jun 18, 2019 · 0 comments

Comments

@remkop
Copy link
Owner

remkop commented Jun 18, 2019

If a command is defined with only named parameters and no positional parameters, and this command is invoked with an empty string as a parameter, the error message is unclear:

#invoke 
<cmd> ""

Actual result:

Unmatched argument: 
Usage: <main class> [--option]
...

Expected result:

Unmatched argument '' at index 0
Usage: <main class> [--option]
...

Breaking Test:

    @Test
    public void testUnmatchedWithEmptyPositional() {
        @Command class App {
            @Option(names = "-x") List<Object> unmatched;
        }
        CommandLine cmd = new CommandLine(new App());
        try {
            cmd.parse("");
            fail("Expected exception");
        } catch (UnmatchedArgumentException ex) {
            assertEquals("Unmatched argument at index 0: ''", ex.getMessage());
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant