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]



Reply via email to