commons-user mailing list archives

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

Based on the Usage Scenarios 
(, (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(
 	at org.apache.commons.cli.Parser.parse(
 	at org.apache.commons.cli.Parser.parse(
 	at CliTest.main(
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")

    Options options = new Options();

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

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

View raw message