commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Neidhart (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CLI-217) Optional partial matching for long options
Date Mon, 11 Feb 2013 13:23:12 GMT

    [ https://issues.apache.org/jira/browse/CLI-217?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13575775#comment-13575775
] 

Thomas Neidhart commented on CLI-217:
-------------------------------------

The patch it not correct, consider the following case:

{noformat}
        String[] args = new String[] {
            "--a"
        };

        Options options = new Options();
        options.addOption(OptionBuilder.withLongOpt("ab").create());
        options.addOption(OptionBuilder.withLongOpt("a").create());

        CommandLine cl = parser.parse(options, args);
        assertTrue("Confirm --a is set", cl.hasOption("a"));
{noformat}

This would result in the option "ab" being set, but not "a".

A correct patch would do:

 * first check if there is an exact match and use this option
 * if no exact match, get all options which start with this option
 ** compute the longest common substring of all returned options with the specified option
 ** take the option which has the longest common substring
 ** if there are several with equal length, throw an ambiguous option exception

                
> Optional partial matching for long options
> ------------------------------------------
>
>                 Key: CLI-217
>                 URL: https://issues.apache.org/jira/browse/CLI-217
>             Project: Commons CLI
>          Issue Type: Improvement
>          Components: Parser
>    Affects Versions: 1.3
>            Reporter: Emmanuel Bourg
>             Fix For: 1.3
>
>         Attachments: optPartialMatch.patch
>
>
> DefaultParser support partial long options (i.e --ver matches --version if there is no
ambiguity), but for some cases it might be necessary to disable this feature.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message