Skip to content

Improve error message for unmatched arguments #733

@remkop

Description

@remkop

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());
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions