Details
Description
MissingArgumentException: no argument for <option> is thrown when the option's
parameter equals to an existing option. Example:
-l option1
-m option2
//this will throw exception
$app -l m
Test case follows:
import junit.framework.*;
import org.apache.log4j.*;
import org.apache.commons.cli.*;
public class CliTest extends TestCase {
CommandLineParser parser;
public CliTest(String name)
{ super(name); }protected void setUp() throws Exception
{ parser = new PosixParser(); } public void testParamNamedAsOption() throws Exception {
final String[] CLI_ARGS = new String[]
;
Option option = new Option("z", "timezone", true,
"affected option");
Options cliOptions = new Options();
cliOptions.addOption(option);
parser.parse(cliOptions, CLI_ARGS);
//now add conflicting option
cliOptions.addOption("c", "conflict", true, "conflict option");
parser.parse(cliOptions, CLI_ARGS);
}
}