commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Darin_Haw...@cargill.com
Subject unexpected parsing behavior
Date Tue, 22 Apr 2003 19:45:35 GMT

Based on the Usage Scenarios 
(http://jakarta.apache.org/commons/cli/usage.html), (in particular the 
ant example), I was expecting to specify options with long names like 
'buildfile'. The behavior I'm seeing would suggest that option names 
must be a single character. I wrote a simple test program below and got 
the following unexpected results. If nothing else, it would seem that 
the HelpFormatter presents an inconsistent picture of what the parser 
expects. Could someone please clarify and/or update the Usage 
Scenarios? Thanks.

----

java CliTest -test hello
org.apache.commons.cli.UnrecognizedOptionException: Unrecognized 
option: -t
 	at org.apache.commons.cli.Parser.processOption(Parser.java:253)
 	at org.apache.commons.cli.Parser.parse(Parser.java:170)
 	at org.apache.commons.cli.Parser.parse(Parser.java:114)
 	at CliTest.main(CliTest.java:18)
usage: command [options]
  -test <testValue>   a test value

----

import org.apache.commons.cli.*;

public class CliTest {

  public static void main(String[] args) throws Exception {

    Option testOption = OptionBuilder.withArgName("testValue")
      .hasArg().withDescription("a test value")
      .create("test");

    Options options = new Options();
    options.addOption(testOption);

    try {
    
      CommandLineParser parser = new PosixParser();
      CommandLine line = parser.parse(options,args);

    } catch (Exception e) {
      e.printStackTrace();
      new HelpFormatter().printHelp("command [options]", options);
    }
  }
}


Mime
View raw message