本文整理匯總了Java中org.apache.commons.cli.CommandLine.hasOption方法的典型用法代碼示例。如果您正苦於以下問題:Java CommandLine.hasOption方法的具體用法?Java CommandLine.hasOption怎麽用?Java CommandLine.hasOption使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.cli.CommandLine
的用法示例。
在下文中一共展示了CommandLine.hasOption方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: transitionToActive
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
private int transitionToActive(final CommandLine cmd)
throws IOException, ServiceFailedException {
String[] argv = cmd.getArgs();
if (argv.length != 1) {
errOut.println("transitionToActive: incorrect number of arguments");
printUsage(errOut, "-transitionToActive");
return -1;
}
/* returns true if other target node is active or some exception occurred
and forceActive was not set */
if(!cmd.hasOption(FORCEACTIVE)) {
if(isOtherTargetNodeActive(argv[0], cmd.hasOption(FORCEACTIVE))) {
return -1;
}
}
HAServiceTarget target = resolveTarget(argv[0]);
if (!checkManualStateManagementOK(target)) {
return -1;
}
HAServiceProtocol proto = target.getProxy(
getConf(), 0);
HAServiceProtocolHelper.transitionToActive(proto, createReqInfo());
return 0;
}
示例2: execute
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook);
adminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
try {
String topic = commandLine.getOptionValue('t').trim();
if (commandLine.hasOption('c')) {
String clusterName = commandLine.getOptionValue('c').trim();
adminExt.start();
deleteTopic(adminExt, clusterName, topic);
return;
}
ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
adminExt.shutdown();
}
}
示例3: execute
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
try {
boolean result = false;
defaultMQAdminExt.start();
if (commandLine.hasOption('b')) {
String addr = commandLine.getOptionValue('b').trim();
result = defaultMQAdminExt.cleanExpiredConsumerQueueByAddr(addr);
} else {
String cluster = commandLine.getOptionValue('c');
if (null != cluster)
cluster = cluster.trim();
result = defaultMQAdminExt.cleanExpiredConsumerQueue(cluster);
}
System.out.printf(result ? "success" : "false");
} catch (Exception e) {
e.printStackTrace();
} finally {
defaultMQAdminExt.shutdown();
}
}
示例4: getProbandListStatusLogLevelOptionValue
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
private static ProbandListStatusLogLevel getProbandListStatusLogLevelOptionValue(CommandLine line, boolean required) throws Exception {
if (required && !line.hasOption(DBToolOptions.PROBAND_LIST_STATUS_LOG_LEVEL_OPT)) {
throw new IllegalArgumentException("proband list status log level required");
}
String option = line.getOptionValue(DBToolOptions.PROBAND_LIST_STATUS_LOG_LEVEL_OPT);
if (!CommonUtil.isEmptyString(option)) {
try {
return ProbandListStatusLogLevel.fromString(option);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("proband list status log level: level name required, one of " + StringUtils.join(ProbandListStatusLogLevel.names(), ", "));
}
} else if (required) {
throw new IllegalArgumentException("empty proband list status log level");
} else {
return null;
}
}
示例5: execute
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook);
adminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
try {
String topic = commandLine.getOptionValue('t').trim();
if (commandLine.hasOption('c')) {
String clusterName = commandLine.getOptionValue('c').trim();
adminExt.start();
deleteTopic(adminExt, clusterName, topic);
return;
}
ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options);
} catch (Exception e) {
e.printStackTrace();
} finally {
adminExt.shutdown();
}
}
示例6: getEmailRecipients
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
private static StringBuilder getEmailRecipients(CommandLine line, boolean send) {
StringBuilder recipients = new StringBuilder();
if (line.hasOption(DBToolOptions.EMAIL_RECIPIENTS_OPT)) {
if (recipients.length() > 0) {
recipients.append(DEFAULT_EMAIL_ADDRESS_SEPARATOR);
}
recipients.append(line.getOptionValue(DBToolOptions.EMAIL_RECIPIENTS_OPT));
}
if (line.hasOption(DBToolOptions.EMAIL_RECIPIENTS_IF_COUNT_GT_ZERO_OPT) && send) {
if (recipients.length() > 0) {
recipients.append(DEFAULT_EMAIL_ADDRESS_SEPARATOR);
}
recipients.append(line.getOptionValue(DBToolOptions.EMAIL_RECIPIENTS_IF_COUNT_GT_ZERO_OPT));
}
return recipients;
}
示例7: applyOptions
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
@Override
/** {@inheritDoc} */
public void applyOptions(CommandLine in, SqoopOptions out)
throws InvalidOptionsException {
if (in.hasOption(TABLE_ARG)) {
out.setTableName(in.getOptionValue(TABLE_ARG));
}
out.setHiveImport(true);
applyCommonOptions(in, out);
applyHiveOptions(in, out);
applyOutputFormatOptions(in, out);
}
示例8: sanityCheckOptions
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
private boolean sanityCheckOptions(CommandLine cmd) {
boolean success = true;
for (String reqOpt : requiredOptions) {
if (!cmd.hasOption(reqOpt)) {
LOG.error("Required option -" + reqOpt + " is missing");
success = false;
}
}
return success;
}
示例9: optionToConf
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
private static void optionToConf(CommandLine cmd, String option,
Configuration conf, String destConfKey) {
if (cmd.hasOption(option)) {
String value = cmd.getOptionValue(option);
LOG.info("Set configuration key:" + destConfKey + " value:" + value);
conf.set(destConfKey, value);
}
}
示例10: main
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
public static void main(String[] args) {
CommandLineParser parser = new DefaultParser();
CommandLine cli = null;
try {
cli = parser.parse(OptionsArgsName.getAllSupportOption(), args);
if (cli.hasOption(OptionsArgsName.HELP)) {
OptionsArgsName.printHelpOption();
return;
}
} catch (ParseException exp) {
System.err.println("Parsing Argument failed. Reason: " + exp.getMessage());
OptionsArgsName.printHelpOption();
return;
}
ConfigReader configReader = new ConfigReader(cli);
if (!configReader.isInitConfigFlag()) {
System.err.println(configReader.getInitErrMsg());
return;
}
Statistics.instance.start();
HdfsToCos hdfsToCos = new HdfsToCos(configReader);
hdfsToCos.run();
Statistics.instance.printStatics();
}
示例11: getAuthenticationOptionValue
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
private static AuthenticationVO getAuthenticationOptionValue(CommandLine line) throws Exception {
if (!line.hasOption(DBToolOptions.USERNAME_OPT)) {
throw new IllegalArgumentException("username required");
}
if (!line.hasOption(DBToolOptions.PASSWORD_OPT)) {
throw new IllegalArgumentException("password required");
}
return new AuthenticationVO(line.getOptionValue(DBToolOptions.USERNAME_OPT), line.getOptionValue(DBToolOptions.PASSWORD_OPT), null, "localhost");
}
示例12: doMain
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
void doMain(String[] args) {
Options o = new Options();
Option help = new Option("h", "help", false,
"display this help message");
o.addOption(help);
Option primes = new Option("p", "primes", true,
"print <count> first prime numbers");
primes.setArgName("count");
o.addOption(primes);
Option generatedBean = new Option("g", "generatedbean", true,
"use generated javabean by setting s=<sValue>");
generatedBean.setArgName("sValue");
o.addOption(generatedBean);
Option unsignedByte = new Option("u", "unsigned-byte", true,
"use joulu-unsigned-byte to convert <int> to"
+ " unsigned byte and display information");
unsignedByte.setArgName("int");
o.addOption(unsignedByte);
CommandLineParser parser = new DefaultParser();
CommandLine cmd;
try {
cmd = parser.parse(o, args);
} catch (ParseException e) {
showHelpAndExit(o);
return;
}
if (cmd.hasOption(help.getOpt())) {
showHelpAndExit(o);
return;
}
if (cmd.hasOption(primes.getOpt())) {
int count = Integer.parseInt(cmd.getOptionValue(primes.getOpt()));
printPrimes(count);
return;
}
if (cmd.hasOption(generatedBean.getOpt())) {
String v = cmd.getOptionValue(generatedBean.getOpt());
useGeneratedBean(v);
return;
}
if (cmd.hasOption(unsignedByte.getOpt())) {
int value = Integer
.parseInt(cmd.getOptionValue(unsignedByte.getOpt()));
useJouluUnsignedByte(value);
return;
}
showHelpAndExit(o);
return;
}
示例13: parse
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
@Override
protected void parse(CommandLine commandLine) {
super.parse(commandLine);
this.server = commandLine.getOptionValue("s", server);
this.quiet = commandLine.hasOption("q");
}
示例14: getDepartmentPassword
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
private static String getDepartmentPassword(CommandLine line) throws Exception {
if (!line.hasOption(DBToolOptions.DEPARTMENT_PASSWORD_OPT)) {
throw new IllegalArgumentException("department password required");
}
return line.getOptionValue(DBToolOptions.DEPARTMENT_PASSWORD_OPT);
}
示例15: getLongOrNull
import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
private Long getLongOrNull(CommandLine cmd, String option) {
if (!cmd.hasOption(option)) return null;
return Long.parseLong(cmd.getOptionValue(option));
}