下面列出了怎么用org.apache.commons.cli.AlreadySelectedException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Handle command line caution group
*
* @return location of the (remote or local) repository
*/
protected boolean handleCautionGroup() {
ConsoleIO io = console.getConsoleIO();
try {
if (commandLine.hasOption(FORCE.getOpt())) {
CAUTION_GROUP.setSelected(FORCE);
io.setForce();
}
if (commandLine.hasOption(CAUTIOUS.getOpt())) {
CAUTION_GROUP.setSelected(CAUTIOUS);
io.setCautious();
}
} catch (AlreadySelectedException e) {
printUsage();
return false;
}
return true;
}
/**
* Handle command line location group
*
* @return location of the (remote or local) repository
*/
protected String handleLocationGroup() {
String location = null;
try {
if (commandLine.hasOption(DIRECTORY.getOpt())) {
LOCATION_GROUP.setSelected(DIRECTORY);
location = commandLine.getOptionValue(DIRECTORY.getOpt());
}
if (commandLine.hasOption(SERVER.getOpt())) {
LOCATION_GROUP.setSelected(SERVER);
location = commandLine.getOptionValue(SERVER.getOpt());
}
} catch (AlreadySelectedException e) {
printUsage();
}
return location;
}
@Test(expected = AlreadySelectedException.class)
public void testBadHelp() throws Exception {
String cl = "systemds -help -clean";
String[] args = cl.split(" ");
DMLOptions o = DMLOptions.parseCLArguments(args);
Assert.assertEquals(true, o.help);
}
@Test
public void testParseArgument_duplicateOptions_coordinates_file() throws ParseException {
try {
DashboardArguments.readCommandLine(
"-c", "com.google.cloud:libraries-bom:1.0.0", "-f", "../pom.xml");
Assert.fail("The argument should validate duplicate input");
} catch (AlreadySelectedException ex) {
// pass
}
}
@Test
public void testParseArgument_duplicateOptions_coordinates_allVersions() throws ParseException {
try {
DashboardArguments.readCommandLine(
"-c", "com.google.cloud:libraries-bom:1.0.0", "-a", "com.google.cloud:libraries-bom");
Assert.fail("The argument should validate duplicate input");
} catch (AlreadySelectedException ex) {
// pass
}
}
@Test(expected = AlreadySelectedException.class)
public void testBadHelp() throws Exception {
String cl = "systemds -help -clean";
String[] args = cl.split(" ");
DMLOptions o = DMLOptions.parseCLArguments(args);
Assert.assertEquals(true, o.help);
}
@Test(expected = AlreadySelectedException.class)
public void testBadClean() throws Exception {
String cl = "systemds -clean -f test.dml";
String[] args = cl.split(" ");
DMLOptions.parseCLArguments(args);
}
@Test(expected = AlreadySelectedException.class)
public void testBadScript() throws Exception {
String cl = "systemds -f test.dml -s \"print('hello')\"";
String[] args = cl.split(" ");
DMLOptions.parseCLArguments(args);
}
@Test(expected = AlreadySelectedException.class)
public void testBadClean() throws Exception {
String cl = "systemds -clean -f test.dml";
String[] args = cl.split(" ");
DMLOptions.parseCLArguments(args);
}
@Test(expected = AlreadySelectedException.class)
public void testBadScript() throws Exception {
String cl = "systemds -f test.dml -s \"print('hello')\"";
String[] args = cl.split(" ");
DMLOptions.parseCLArguments(args);
}