John,
This is a test which does not work for me.
It parses the command line without throwing an exception.
Thanks
robert
import org.apache.commons.cli.*;
import org.apache.commons.cli.Options;
public class test1 {
public test1() {
}
/**
*
* @param args
*/
public static void main(String[] args) {
test1 test1 = new test1();
// create Options object
try {
Options options = new Options();
Event event = new Event();
// add c option
options.addOption("j", true, "Ejb_host");
options.getOption("j").setRequired(true);
options.addOption("u", true, "Scauto_evuser");
options.addOption("y", true, "Scauto_sepchar");
options.addOption("f", true, "Fields");
options.getOption("f").setRequired(true);
// parse the command line arguments
CommandLineParser parser = new PosixParser();
CommandLine cmd = parser.parse(options, args);
} catch (ParseException e) {
if ((e instanceof MissingOptionException)) {
System.err.println("Error processing command line. Missing Option.\n");
} else if ((e instanceof MissingArgumentException)) {
System.err.println(
"Error processing command line. Missing option Argument.\n.");
} else if ((e instanceof UnrecognizedOptionException)) {
System.err.println(
"Error processing command line. Unrecognize Option.\n.");
} else {
System.err.println("Error processing command line.\n.");
}
}
}
}
-----Original Message-----
From: John Keyes [mailto:[EMAIL PROTECTED]
Sent: Monday, October 20, 2003 6:35 PM
To: Jakarta Commons Users List
Subject: Re: CLI: I never get exception when parsing a command line
Hi Robert,
Can you supply some test code for this?
Thanks,
-John K
On Monday, Oct 20, 2003, at 23:11 Europe/Dublin, Augustyn, Robert non
Unisys wrote:
> Hi,
> I was expecting that when a required option is missing from the
> command like an exception would be thrown but nothing like that.
> Same when I add invalid option. Parser seems to be processing command
> line without throwing an exception.
> I am assuming that I am doing something wrong because this would come
> up in the archive but I have not seen anything related to this > problem.
> Thanks in advance.
> robert
>
> ---------------------------------------------------------------------
> 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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]