commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Heger (JIRA)" <>
Subject [jira] Updated: (CLI-150) Negative numbers mistaken for options
Date Thu, 17 Jul 2008 19:39:31 GMT


Oliver Heger updated CLI-150:


This is a tough one.

The problem is caused by the processArguments() method of ArgumentImpl. This method tries
to determine all values that belong to the argument. For each element of the command line
it calls commandLine.looksLikeOption() to check whether a new option starts (and thus the
argument list is complete). looksLikeOption() is probably a bit over-simplified. It just checks
whether the element starts with a prefix that indicates an option (per default "--" and "-").
Here the "-" of the negative number is interpreted as start of a new option.

Attached is a unit test demonstrating the problem. It was created based on the original bug

> Negative numbers mistaken for options
> -------------------------------------
>                 Key: CLI-150
>                 URL:
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-2.x
>         Environment: Sun JDK 1.6, Ubuntu 7.04
>            Reporter: Dioktos
>             Fix For: 2.0
>         Attachments:
> If an option has a negative numerical argument, the parser mistakes it for another option
and throws an error. For example, consider:
> {{Argument numArg = aBuilder.withValidator(NumberValidator.getNumberInstance()).withMinimum(1).withMaximum(1).create();}}
> {{Option numOpt = oBuilder.withLongName("num").withArgument(numArg).create();}}
> {{Group options = gBuilder.withOption(numOpt).create();}}
> Then parsing {{--num -0.1}} results in:
> {{Unexpected -0.1 while processing --num}}

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message