本文整理汇总了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));
}