You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Lynn Henderson (JIRA)" <ji...@apache.org> on 2016/05/05 22:35:12 UTC
[jira] [Commented] (CLI-265) Optional argument picking up next
regular option as its argument
[ https://issues.apache.org/jira/browse/CLI-265?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15273243#comment-15273243 ]
Lynn Henderson commented on CLI-265:
------------------------------------
I have recently migrated a project from CLI 1.2 to 1.3.1 and have encountered what may be a bug or difference in the way optional arguments are being processed.
I have a command that opens several different kinds of databases by type, or alternately, the last opened database of that type.
Option TYPE1 = Option.builder("t1").hasArg().numberOfArgs(1).optionalArg(true).argName("t1_path").build();
Option TYPE2 = Option.builder("t2").hasArg().numberOfArgs(1).optionalArg(true).argName("t2_path").build();
Option LAST = Option.builder("last").hasArg(false).build();
Commands then look like "open -t1 path/to/my/db" or "open -t1 -last"
If I use the now deprecated GnuParser, both commands work as expected. However, if I use the new DefaultParser, for the 2nd example, it thinks "-last" is the argument for -t1 rather than an option in its own right.
I added the numberOfArgs(1) after reading a post on StackOverflow, but it made no difference in the behavior. Only switching back to the GnuParser seemed to work.
> Optional argument picking up next regular option as its argument
> ----------------------------------------------------------------
>
> Key: CLI-265
> URL: https://issues.apache.org/jira/browse/CLI-265
> Project: Commons CLI
> Issue Type: Bug
> Components: CLI-1.x
> Affects Versions: 1.3.1
> Reporter: Lynn Henderson
>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)