本文整理汇总了Java中org.apache.commons.cli.MissingOptionException类的典型用法代码示例。如果您正苦于以下问题:Java MissingOptionException类的具体用法?Java MissingOptionException怎么用?Java MissingOptionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MissingOptionException类属于org.apache.commons.cli包,在下文中一共展示了MissingOptionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkRequiredOptions
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
public static void checkRequiredOptions() throws MissingOptionException {
OptionGroup[] groups = {contentGroup};
for(OptionGroup group : groups) {
ArrayList<Option> groupOptions = new ArrayList<Option>(group.getOptions());
boolean groupIsGiven = false;
for (Option option : groupOptions){
if (commandLine.hasOption(option.getOpt())) {
groupIsGiven = true;
break;
}
}
if (!groupIsGiven){
throw new MissingOptionException(groupOptions);
}
}
}
示例2: process
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static String process(ParseException e) {
if (e instanceof MissingOptionException) {
StringBuilder sb = new StringBuilder();
Iterator<String> options = ((MissingOptionException) e).getMissingOptions().iterator();
while (options.hasNext()) {
sb.append(options.next());
if (options.hasNext()) {
sb.append(", ");
}
}
return String.format("Missing required option(s) %s.", sb.toString());
}
else if (e instanceof MissingArgumentException) {
return String.format("%s is missing a required argument.",
((MissingArgumentException) e).getOption());
}
else if (e instanceof UnrecognizedOptionException) {
return String.format("%s is not a valid option.",
((UnrecognizedOptionException) e).getOption());
}
else {
return String.format("%s.", e.getMessage());
}
}
示例3: checkRequiredOptions
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
public static void checkRequiredOptions() throws MissingOptionException {
OptionGroup[] groups = {typeGroup, contentGroup};
for(OptionGroup group : groups) {
ArrayList<Option> groupOptions = new ArrayList<Option>(group.getOptions());
boolean groupIsGiven = false;
for (Option option : groupOptions){
if (commandLine.hasOption(option.getOpt())) {
groupIsGiven = true;
break;
}
}
if (!groupIsGiven){
throw new MissingOptionException(groupOptions);
}
}
}
示例4: checkRequiredOptions
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
/**
* Checks for the presence of the required options.
*
* @throws MissingOptionException if a required options is not provided.
*/
private void checkRequiredOptions() throws MissingOptionException {
String missingOptions = "";
ConfigManager config = ConfigManager.getInstance();
if (config.className == null) {
missingOptions += CLZ.getSwitches();
}
if (config.args == null) {
if (missingOptions.length() > 0)
missingOptions += ", ";
missingOptions += ARGS.getSwitches();
}
if (missingOptions.length() > 0) {
throw new MissingOptionException(missingOptions);
}
}
示例5: parseArgs
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
/**
* Parse the command line arguments.
*/
protected static CommandLine parseArgs(String[] args) {
CommandLine cl = null;
try {
cl = argParser.parse(cmdOptions, args);
} catch (AlreadySelectedException dupex) {
displayHelp();
display("\nDuplicate option: " + dupex.getMessage());
} catch (MissingOptionException opex) {
displayHelp();
display("\nMissing command line option: " + opex.getMessage());
} catch (UnrecognizedOptionException uex) {
displayHelp();
display(uex.getMessage());
} catch (ParseException pe) {
display("Unable to parse the command line arguments: " + pe);
} catch (Exception ex) {
ex.printStackTrace();
}
return cl;
}
示例6: parseCli
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
public static CommandLine parseCli(ModeType mode, String[] args) {
CommandLine cli = null;
Options opt = ConfigModes.getMode(mode);
try {
cli = new IgnorePosixParser(true).parse(opt, args);
} catch (MissingArgumentException me) {
Formatter.usageError(me.getLocalizedMessage(), mode);
System.exit(-1);
} catch (MissingOptionException mo) {
Formatter.usageError(mo.getLocalizedMessage(), mode);
System.exit(-1);
} catch (AlreadySelectedException ase) {
Formatter.usageError(ase.getLocalizedMessage(), mode);
} catch (UnrecognizedOptionException uoe) {
Formatter.usageError(uoe.getLocalizedMessage(), mode);
} catch (ParseException e) {
Formatter.printStackTrace(e);
System.exit(-1);
}
return cli;
}
示例7: checkRequiredOptions
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
protected void checkRequiredOptions() throws MissingOptionException {
List requiredOptions = this.getRequiredOptions();
if (!requiredOptions.isEmpty()) {
Iterator it = requiredOptions.iterator();
while (it.hasNext()) {
Object opt = it.next();
if (opt.getClass().equals(String.class)) {
if (Configuration.has(((String) opt))) {
it.remove();
}
} else if (opt.getClass().equals(Option.class)) {
if (Configuration.has(((Option) opt).getLongOpt())) {
it.remove();
}
}
}
}
if (!requiredOptions.isEmpty()) {
throw new MissingOptionException(requiredOptions);
}
}
示例8: tryParse
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
public static CommandLine tryParse(CommandLineParser parser, Options options,
String[] args) {
try {
return parser.parse(options, args);
} catch (MissingOptionException moe) {
logger.error("Required options missing: " + Joiner.on(',').join(moe.getMissingOptions()));
throw new CliParser.ParsingException(moe);
} catch (ParseException e) {
logger.error("Failed parsing options", e);
throw new CliParser.ParsingException(e);
}
}
示例9: testGetChangeStatusNoPassword
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
@Test
public void testGetChangeStatusNoPassword() throws Exception {
thrown.expect(MissingOptionException.class);
thrown.expectMessage("Missing required option: p");
//
// Comment line below in order to go against the real back-end as specified via -h
setMock(setupMock());
GetChangeStatus.main(new String[] {
"-u", SERVICE_USER,
"-e", SERVICE_ENDPOINT,
"8000038673"});
}
示例10: testFailOnMissingMandatoryOption
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
@Test(expected = MissingOptionException.class)
public void testFailOnMissingMandatoryOption() throws Exception {
// Test for a help dialog displayed upon failure
String[] args = {"-s 0"};
ConfigurationBuilder.createBuilder()
.loadCommandLineConfiguration(CLIConstants.setupOptions(), args)
.getConfiguration();
}
示例11: testHelpFromFail
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
@Test(expected = MissingOptionException.class)
public void testHelpFromFail() throws Exception {
// First test for a user requested help dialog
String[] args = {"--help"};
ConfigurationBuilder.createBuilder()
.loadCommandLineConfiguration(CLIConstants.setupOptions(), args)
.getConfiguration();
}
示例12: checkNoArg
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
/**
* Checks if specifying no arg works.
*/
@Test
public void checkNoArg() throws KeywordOptimizerException {
thrown.expect(KeywordOptimizerException.class);
thrown.expectCause(isA(MissingOptionException.class));
KeywordOptimizer.main(new String[]{});
}
示例13: afterParseChecks
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
public static void afterParseChecks() throws MissingOptionException {
if (commandLine.hasOption("h")) {
System.out.println("You passed help flag.");
help(0);
} else if (commandLine.hasOption("v")) {
printVersions();
}else {
checkRequiredOptions();
}
}
示例14: afterParseChecks
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
public static void afterParseChecks() throws MissingOptionException{
if (commandLine.hasOption("h")) {
System.out.println("You passed help flag.");
help(0);
} else if (commandLine.hasOption("v")) {
printVersions();
} else {
checkRequiredOptions();
}
}
示例15: testParseArgumentsFailOnMissingArgumentTrue
import org.apache.commons.cli.MissingOptionException; //导入依赖的package包/类
@Test(expected = MissingOptionException.class)
public void testParseArgumentsFailOnMissingArgumentTrue() throws ParseException
{
// Create an argument parser with a required "a" option.
ArgumentParser argParser = new ArgumentParser("");
argParser.addArgument("a", "some_optional_parameter", false, "Some argument", true);
// Parse the arguments with a missing argument which should thrown an exception since we are passing the flag which WILL fail on missing arguments.
argParser.parseArguments(new String[] {}, true);
}