I'm a bit short of (online) time at the moment, so it may be a day or two before I can have a proper look at this and the bugzilla patches.

In the meantime, it might be worth checking up on the differences between the PosixParser and GnuParser, one of them (posix I think) will take the string "-time" and burst it into "-t -i -m -e" before parsing. This seems to be related to the DateApp issue you are seeing, and I suspect the ant example uses that alternative parser. Either way, the error message is misleading at best.

Rob

Dennis Lundberg wrote:

I have used the examples at
http://jakarta.apache.org/commons/cli/usage.html
to learn commons-cli. They do a good job at introducing new users to the functionality of commons-cli.


There was one thing that was not clear to me when I read the examples or source. Here is a slightly modified version of the DateApp example from the URL above.

--- Start code ---
public class DateApp {
  public static void main(String[] args) {
    // create Options object
    Options options = new Options();

    // add t option
    options.addOption("time", false, "display current time");

    CommandLineParser parser = new PosixParser();

    try {
      CommandLine cmd = parser.parse(options, args);

if(cmd.hasOption("time")) {
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
}
else {
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
}
}
catch(ParseException exp) {
// oops, something went wrong
System.err.println("Parsing failed. Reason: " + exp.getMessage());
}
}
}
--- End code ---


If I try
 > java DateApp
it prints the date as expected

If I try
 > java DateApp -t
it just prints the date

If I try
 > java DateApp -time
it fails with this error:
  "Parsing failed.  Reason: Unrecognized option: -t"

Now to the question:
Is a single-hyphen-option like "-help" not allowed to have more than one character after the hyphen? If that is the case then the Ant example in the usage document does not work.


--
Dennis Lundberg


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to