本文整理匯總了Java中org.apache.commons.cli.UnrecognizedOptionException類的典型用法代碼示例。如果您正苦於以下問題:Java UnrecognizedOptionException類的具體用法?Java UnrecognizedOptionException怎麽用?Java UnrecognizedOptionException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
UnrecognizedOptionException類屬於org.apache.commons.cli包,在下文中一共展示了UnrecognizedOptionException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseArgs
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的package包/類
/**
* Parses the command line arguments and returns a Configuration according to the given
* switches.
* @param args the command line arguments given to main
* @return the configuration
* @throws ParseException
*/
public Configuration parseArgs(String[] args) throws ParseException {
CommandLine cl = null;
try {
cl = parser.parse(options, args);
} catch (UnrecognizedOptionException uoe){
logger.error("unrecognized option: {}",uoe.getOption());
printHelp();
System.exit(1);
}
Configuration config = new Configuration();
if(!cl.hasOption('c')){
config.setTargetCount(1);
} else {
config.setTargetCount(Long.parseLong(cl.getOptionValue('c')));
}
if(!cl.hasOption('p')){
config.setUserNamePrefix("user");
} else {
config.setUserNamePrefix(cl.getOptionValue('p'));
}
return config;
}
示例2: process
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的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: parseArgs
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的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;
}
示例4: parseCli
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的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;
}
示例5: parseArgs
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的package包/類
/**
* Parses the command line arguments and returns a Configuration according to the given
* switches.
* @param args the command line arguments given to main
* @return the configuration
* @throws ParseException
*/
public Configuration parseArgs(String[] args) throws ParseException {
CommandLine cl = null;
try {
cl = parser.parse(options, args);
} catch (UnrecognizedOptionException uoe){
logger.error("unrecognized option: {}",uoe.getOption());
printHelp();
System.exit(1);
}
Configuration config = new Configuration();
config.setLoginUrl(cl.getOptionValue('t'));
if(!cl.hasOption('l')){
config.setLoops(1);
} else {
config.setLoops(Long.parseLong(cl.getOptionValue('l')));
}
if(!cl.hasOption('r')){
config.setRequestsPerMinute(-1);
} else {
config.setRequestsPerMinute(Long.parseLong(cl.getOptionValue('r')));
}
if(!cl.hasOption('i')){
config.setOriginIpAddress(null);
} else {
config.setOriginIpAddress(cl.getOptionValue('i'));
}
config.setCredentials(getCredentials(cl.getOptionValue('f'), cl.getOptionValues('c')));
if (!ConfigurationValidator.isValid(config)){
printHelp();
}
return config;
}
示例6: checkRandomArgDoesNotWork
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的package包/類
/**
* Checks if the specifying some random argument work throws an exception.
*/
@Test
public void checkRandomArgDoesNotWork() throws KeywordOptimizerException {
thrown.expect(KeywordOptimizerException.class);
thrown.expectCause(isA(UnrecognizedOptionException.class));
KeywordOptimizer.run("-x");
}
示例7: testParseArgumentsUnrecognizedOptionException
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的package包/類
@Test(expected = UnrecognizedOptionException.class)
public void testParseArgumentsUnrecognizedOptionException() throws ParseException
{
ArgumentParser argParser = new ArgumentParser("");
argParser.addArgument("a", "configured_option", false, "Some flag parameter", false);
argParser.parseArguments(new String[] {"-b", "unrecognized_option"});
}
示例8: validateProperties
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的package包/類
/**
* Verifies that the properties don't contain undefined options which will
* cause the base parser to blowup.
*
* @param options the options config
* @param properties overriding properties
* @throws UnrecognizedOptionException if a property exists that isn't
* configured in the options.
*/
protected void validateProperties(Options options, Properties properties)
throws UnrecognizedOptionException {
if (properties != null) {
for (Entry<Object, Object> e : properties.entrySet()) {
String arg = (String) e.getKey();
boolean hasOption = options.hasOption(arg);
if (!hasOption) {
throw new UnrecognizedOptionException(
"Unrecognized option: " + arg, arg);
}
}
}
}
示例9: main
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
Options options = new Options();
options.addOption(OPT_CONFIGFILE, true,
"The XML Configuration file describing what to anonymize.");
options.addOption(OPT_SYNONYMFILE, true,
"The XML file to read/write synonyms to. "
+ "If the file does not exist it will be created.");
options.addOption("configexample", false,
"Prints out a demo/template configuration file.");
options.addOption(OPT_DRYRUN, false, "Do not make changes to the database.");
BasicParser parser = new BasicParser();
try {
CommandLine commandline = parser.parse(options, args);
String configfileName = commandline.getOptionValue(OPT_CONFIGFILE);
String synonymfileName = commandline.getOptionValue(OPT_SYNONYMFILE);
boolean dryrun = commandline.hasOption(OPT_DRYRUN);
if (configfileName != null) {
anonymize(configfileName, synonymfileName, dryrun);
} else if (commandline.hasOption("configexample")) {
printDemoConfiguration();
} else {
printHelp(options);
}
} catch (UnrecognizedOptionException e) {
System.err.println(e.getMessage());
printHelp(options);
}
}
示例10: getReservationACLFromAuditConstant
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的package包/類
private ReservationACL getReservationACLFromAuditConstant(
String auditConstant) throws YarnException{
if (auditConstant.equals(AuditConstants.SUBMIT_RESERVATION_REQUEST)) {
return ReservationACL.SUBMIT_RESERVATIONS;
} else if (auditConstant.equals(AuditConstants.LIST_RESERVATION_REQUEST)) {
return ReservationACL.LIST_RESERVATIONS;
} else if (auditConstant.equals(AuditConstants.DELETE_RESERVATION_REQUEST)
|| auditConstant.equals(AuditConstants.UPDATE_RESERVATION_REQUEST)) {
return ReservationACL.ADMINISTER_RESERVATIONS;
} else {
String error = "Audit Constant " + auditConstant + " is not recognized.";
LOG.error(error);
throw RPCUtil.getRemoteException(new UnrecognizedOptionException(error));
}
}
示例11: execute
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的package包/類
@Override
public void execute(CommandLine options) throws Exception {
String[] args = options.getArgs();
if (args.length < min) {
throw new MissingArgumentException("missing required arguments");
}
if (args.length > max) {
throw new UnrecognizedOptionException("unknown extra argument \"" + args[max] + "\"");
}
}
示例12: testParseCommandLine_InvalidArguments_ThrowsException
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的package包/類
/**
* Invalid arguments on the command line result in an exception.
*
* @throws Exception
*/
@Test
public void testParseCommandLine_InvalidArguments_ThrowsException() throws Exception {
// Setup
final StartApplication main = new StartApplication();
thrown.expect(UnrecognizedOptionException.class);
thrown.expectMessage("Unrecognized option: -foo");
// Run
main.parseCommandLine(new String[] { "-foo" });
}
示例13: mainPrintUsage5Test
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的package包/類
@Test(expected = UnrecognizedOptionException.class)
public void mainPrintUsage5Test() throws Exception {
Main.main(new String[]{"-nifi","http://localhost:8080/nifi-api", "-branch","\"root>N2\"","-conf","adr","-m","undeploy", "-userErr","user"});
}
示例14: testParseCommandLine_withUnknownSettings
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的package包/類
/**
* Test case for {@link StreamingAppRuntime#parseCommandLine(String[])} being
* provided an array showing unknown settings
*/
@Test(expected=UnrecognizedOptionException.class)
public void testParseCommandLine_withUnknownSettings() throws Exception {
new DummyLogProcessingRuntime(new CountDownLatch(1)).parseCommandLine(new String[]{"-a","123"});
}
示例15: testParseCommandLine_withKnownAndUnknownSettings
import org.apache.commons.cli.UnrecognizedOptionException; //導入依賴的package包/類
/**
* Test case for {@link StreamingAppRuntime#parseCommandLine(String[])} being
* provided an array showing known and unknown settings
*/
@Test(expected=UnrecognizedOptionException.class)
public void testParseCommandLine_withKnownAndUnknownSettings() throws Exception {
new DummyLogProcessingRuntime(new CountDownLatch(1)).parseCommandLine(new String[]{"-a","123", "-f", "/tmp/file.txt"});
}