当前位置: 首页>>代码示例>>Java>>正文


Java MissingOptionException类代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:Ericsson,项目名称:eiffel-remrem-publish,代码行数:17,代码来源:CliOptions.java

示例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());
    }
}
 
开发者ID:atomist-attic,项目名称:rug-cli,代码行数:26,代码来源:ParseExceptionProcessor.java

示例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);
		}
	}
}
 
开发者ID:Ericsson,项目名称:eiffel-remrem-generate,代码行数:17,代码来源:CLIOptions.java

示例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);
    }
}
 
开发者ID:korat-jenkins,项目名称:korat,代码行数:21,代码来源:ConfigLoader.java

示例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;
}
 
开发者ID:ModelN,项目名称:build-management,代码行数:25,代码来源:CMnCmdLineTool.java

示例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;
}
 
开发者ID:cyso,项目名称:vcloud-client,代码行数:23,代码来源:Configuration.java

示例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);
	}
}
 
开发者ID:cyso,项目名称:vcloud-client,代码行数:23,代码来源:IgnorePosixParser.java

示例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);
  }
}
 
开发者ID:spotify,项目名称:spydra,代码行数:14,代码来源:CliHelper.java

示例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"});
}
 
开发者ID:SAP,项目名称:devops-cm-client,代码行数:16,代码来源:GetChangeStatusTest.java

示例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();

}
 
开发者ID:XIVStats,项目名称:XIVStats-Gatherer-Java,代码行数:11,代码来源:ConfigurationBuilderTest.java

示例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();
}
 
开发者ID:XIVStats,项目名称:XIVStats-Gatherer-Java,代码行数:10,代码来源:ConfigurationBuilderTest.java

示例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[]{});
}
 
开发者ID:googleads,项目名称:keyword-optimizer,代码行数:10,代码来源:CommandLineTest.java

示例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();
    }
}
 
开发者ID:Ericsson,项目名称:eiffel-remrem-publish,代码行数:11,代码来源:CliOptions.java

示例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();
	 }
}
 
开发者ID:Ericsson,项目名称:eiffel-remrem-generate,代码行数:11,代码来源:CLIOptions.java

示例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);
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:11,代码来源:ArgumentParserTest.java


注:本文中的org.apache.commons.cli.MissingOptionException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。