You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by De...@emc.com on 2003/02/14 14:45:51 UTC

[CLI] RESEND: Inconsistency in Options.hasOption(String)

Hello,

I think there is an inconsistency in the method Options.hasOption(String).
The Javadoc mentions that the method argument is either the long or short
name of the option. However, the following snippet doesn't give me the
expected results.

org.apache.commons.cli.Options options = new
org.apache.commons.cli.Options();
options.addOption(org.apache.commons.cli.OptionBuilder
.withLongOpt("cluster")
.create());

System.out.println("Has long  'cluster' option? " +
options.hasOption("cluster"));
System.out.println("Has short 'cluster' option? " + options.hasOption(" "));

The output is:

Has long  'cluster' option? false
Has short 'cluster' option? true

However, if I specify this:

System.out.println("Has long  'cluster' option? " +
options.hasOption("--cluster"));

The output is:

Has long  'cluster' option? true

Why should I specify the "--" for the long option and not "-" for the short
one? I think you should only have to specify the short or long option name
withouth any colon (as documented).

Ringo

Re: [CLI] RESEND: Inconsistency in Options.hasOption(String)

Posted by John Keyes <jb...@mac.com>.
Hi Ringo,

The behaviour you describe is incorrect.  I have this on my todo
list (sorry for not responding to your first mail).

-John K

On Friday, Feb 14, 2003, at 13:45 Europe/Dublin, DeSmet_Ringo@emc.com 
wrote:

> Hello,
>
> I think there is an inconsistency in the method 
> Options.hasOption(String).
> The Javadoc mentions that the method argument is either the long or 
> short
> name of the option. However, the following snippet doesn't give me the
> expected results.
>
> org.apache.commons.cli.Options options = new
> org.apache.commons.cli.Options();
> options.addOption(org.apache.commons.cli.OptionBuilder
> .withLongOpt("cluster")
> .create());
>
> System.out.println("Has long  'cluster' option? " +
> options.hasOption("cluster"));
> System.out.println("Has short 'cluster' option? " + 
> options.hasOption(" "));
>
> The output is:
>
> Has long  'cluster' option? false
> Has short 'cluster' option? true
>
> However, if I specify this:
>
> System.out.println("Has long  'cluster' option? " +
> options.hasOption("--cluster"));
>
> The output is:
>
> Has long  'cluster' option? true
>
> Why should I specify the "--" for the long option and not "-" for the 
> short
> one? I think you should only have to specify the short or long option 
> name
> withouth any colon (as documented).
>
> Ringo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
- - - - - - - - - - - - - - - - - - - - - - -
Jakarta Commons CLI
http://jakarta.apache.org/commons/cli