You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Razvan Surdulescu <ra...@post.harvard.edu> on 2003/05/21 20:10:30 UTC

[CLI] Documentation problems?

There seem to be some problems in the CLI documentation:
http://jakarta.apache.org/commons/cli/usage.html

1. In the section entitled "Parsing the command line arguments", the
following code does not compile since Options does not have a parse()
method:

CommandLine cmd = options.parse(args);

2. I am not able to have command line options of the form "-word" where
"word" is longer than 1 letter, although the documentation seems to imply
that this should be possible via the "ANT Example".

Specifically, the following snippet:

        Options options = new Options();
        options.addOption(OptionBuilder
                .withDescription("dynamically generate mining model XML")
                .create("generate"));

        CommandLineParser parser = new PosixParser();
        try {
            CommandLine line = parser.parse(options, args);
        } catch (ParseException pe) {
            System.err.println(pe.getMessage());
        }

fails with:

Unrecognized option: -g

when I execute it with:

javaw.exe -classpath commons-cli-1.0.jar Test -generate

Re: [CLI] Documentation problems?

Posted by John Keyes <jb...@mac.com>.
On Wednesday, May 21, 2003, at 19:10 Europe/Dublin, Razvan Surdulescu 
wrote:

> There seem to be some problems in the CLI documentation:
> http://jakarta.apache.org/commons/cli/usage.html
>
> 1. In the section entitled "Parsing the command line arguments", the
> following code does not compile since Options does not have a parse()
> method:
>
> CommandLine cmd = options.parse(args);
That is a documentation problem.  It should be the parse method on
the parser that is called not the method on Options (older version).
Look for the 'Create the Parser' section in usage.html that details
this.

> 2. I am not able to have command line options of the form "-word" where
> "word" is longer than 1 letter, although the documentation seems to 
> imply
> that this should be possible via the "ANT Example".
>
> Specifically, the following snippet:
>
>         Options options = new Options();
>         options.addOption(OptionBuilder
>                 .withDescription("dynamically generate mining model 
> XML")
>                 .create("generate"));
>
>         CommandLineParser parser = new PosixParser();
>         try {
>             CommandLine line = parser.parse(options, args);
>         } catch (ParseException pe) {
>             System.err.println(pe.getMessage());
>         }
>
> fails with:
>
> Unrecognized option: -g
>
> when I execute it with:
>
> javaw.exe -classpath commons-cli-1.0.jar Test -generate
>
> From what I can tell by looking at the code, 
> PosixParser.burstToken(...)
> expects tokens that are length 1 only.
>
> I am using CLI 1.0 (downloaded it today).
You should use the GnuParser instead of the PosixParser for this so 
that too
is a documentation error.


-John K
- - - - - - - - - - - - - - - - - - - - - - -
Jakarta Commons CLI
http://jakarta.apache.org/commons/cli