Skip to content

Undefined short options are misinterpreted as positional parameter #149

@giaco777

Description

@giaco777

I use picocli and entered an undefined short option like e.g. '-x' on the command line as the first argument
in the list like so:

-x -v -g abc def

This short option is not defined in the @Options/@parameter definition. When running, it confused the interpreter such, that none of the following command line arguments is parsed correctly anymore. No UnmatchedArgumentException is thrown!

I guess, I found the reason. In line 1330 of CommandLine.java there is a check of the length of the argument:

else if (arg.length() > 2 && arg.startsWith("-")) {

I my case the arg length is 2 and therefore it is not recognized as a short option. As a consequence the positional parameter processing is entered.

I changed the line such:

else if (arg.length() >= 2 && arg.startsWith("-")) {

and now it seems to work properly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions