[prev in list] [next in list] [prev in thread] [next in thread]
List: jakarta-commons-user
Subject: [cli]MissingOptionException not being thrown
From: Abhijith Madhav <browseanddownload () gmail ! com>
Date: 2011-06-29 3:35:29
Message-ID: 4E0A9AB1.9080102 () gmail ! com
[Download RAW message or body]
I am unable to make an option as a required option. This happens when I
use it's 'setRequired' method after getting a handle to the 'Option'
object through the 'Options' object's 'getOption' method.
CODE
----
"
Options options = new Options();
options.addOption("a1", true, "abcd");
options.getOption("a1").setRequired(true);
boolean caught = false;
try {
CommandLineParser parser = new PosixParser();
CommandLine cmd = parser.parse(options, args);
} catch (ParseException e) {
System.out.println(e);
caught = true;
}
if (!caught)
System.out.println("Not caught");
"
OUTPUT
------
"
java SortCompare
Not caught
"
However if I create an 'Option' object explicitly, call its
'setRequired' method and then add this object to an 'Options' object,
things work fine.
CODE
----
"
Option opt = new Option("a1", true, "abcd");
opt.setRequired(true);
options.addOption(opt);
try {
CommandLineParser parser = new PosixParser();
CommandLine cmd = parser.parse(options, args);
} catch (ParseException e) {
System.out.println(e);
}
"
OUTPUT
------
"
java SortCompare
org.apache.commons.cli.MissingOptionException: Missing required options: a1
"
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic