本文整理汇总了Java中org.apache.commons.cli.CommandLine.getOptionValue方法的典型用法代码示例。如果您正苦于以下问题:Java CommandLine.getOptionValue方法的具体用法?Java CommandLine.getOptionValue怎么用?Java CommandLine.getOptionValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.cli.CommandLine
的用法示例。
在下文中一共展示了CommandLine.getOptionValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
/**
* Executable function to demonstrate Apache Commons CLI
* parsing of command-line arguments.
*
* @param arguments Command-line arguments to be parsed.
*/
public static void main(final String[] arguments)
{
final Options options = generateOptions();
if (arguments.length < 1)
{
printUsage(options);
printHelp(options);
System.exit(-1);
}
final CommandLine commandLine = generateCommandLine(options, arguments);
// "interrogation" stage of processing with Apache Commons CLI
if (commandLine != null)
{
final boolean verbose =
commandLine.hasOption(VERBOSE_OPTION);
final String fileName =
commandLine.getOptionValue(FILE_OPTION);
out.println("The file '" + fileName + "' was provided and verbosity is set to '" + verbose + "'.");
}
}
示例2: 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();
}
}
示例3: processBaseOptions
import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
/**
* This allows tests that subclass children of this base class such as
* {@link org.apache.hadoop.hbase.test.IntegrationTestReplication} to
* include the base options without having to also include the options from the test.
*
* @param cmd the command line
*/
protected void processBaseOptions(CommandLine cmd) {
if (cmd.hasOption(MONKEY_LONG_OPT)) {
monkeyToUse = cmd.getOptionValue(MONKEY_LONG_OPT);
}
if (cmd.hasOption(NO_CLUSTER_CLEANUP_LONG_OPT)) {
noClusterCleanUp = true;
}
monkeyProps = new Properties();
if (cmd.hasOption(CHAOS_MONKEY_PROPS)) {
String chaosMonkeyPropsFile = cmd.getOptionValue(CHAOS_MONKEY_PROPS);
if (StringUtils.isNotEmpty(chaosMonkeyPropsFile)) {
try {
monkeyProps.load(this.getClass().getClassLoader()
.getResourceAsStream(chaosMonkeyPropsFile));
} catch (IOException e) {
LOG.warn(e);
System.exit(EXIT_FAILURE);
}
}
}
}
示例4: execute
import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
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.cleanUnusedTopicByAddr(addr);
} else {
String cluster = commandLine.getOptionValue('c');
if (null != cluster)
cluster = cluster.trim();
result = defaultMQAdminExt.cleanUnusedTopicByAddr(cluster);
}
System.out.printf(result ? "success" : "false");
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
defaultMQAdminExt.shutdown();
}
}
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:26,代码来源:CleanUnusedTopicCommand.java
示例5: intArgument
import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
/**
* Extracts an integer argument with specified default value.
*/
private int intArgument(CommandLine cli, String argName, int default_) {
String o = cli.getOptionValue(argName);
if (o == null) {
return default_;
} else {
return Integer.parseInt(o);
}
}
示例6: 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.cleanUnusedTopicByAddr(addr);
}
else {
String cluster = commandLine.getOptionValue('c');
if (null != cluster)
cluster = cluster.trim();
result = defaultMQAdminExt.cleanUnusedTopicByAddr(cluster);
}
System.out.println(result ? "success" : "false");
}
catch (Exception e) {
e.printStackTrace();
}
finally {
defaultMQAdminExt.shutdown();
}
}
示例7: main
import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
public static void main(String[] args) {
Options options = new Options();
options.addOption("h", true, "Messaging host");
options.addOption("p", true, "Messaging port");
options.addOption("q", true, "Queue");
options.addOption("u", false, "Print this help");
CommandLineParser parser = new DefaultParser();
try {
CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption("u")) {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("Sender", options);
} else {
String messagingHost = cmd.getOptionValue("h", MESSAGING_HOST);
int messagingPort = Integer.parseInt(cmd.getOptionValue("p", String.valueOf(MESSAGING_PORT)));
String address = cmd.getOptionValue("q", QUEUE);
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory");
props.put("connectionfactory.myFactoryLookup", String.format("amqp://%s:%d", messagingHost, messagingPort));
props.put("queue.myDestinationLookup", address);
LOG.info("Starting client : connecting to [{}:{}]", messagingHost, messagingPort);
Client sender = new Client();
sender.run(props);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
示例8: processOptions
import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
@Override
protected void processOptions(CommandLine cmd) {
int minValueSize = 0, maxValueSize = 0;
String valueSize = cmd.getOptionValue(VALUE_SIZE_KEY, VALUE_SIZE_DEFAULT);
if (valueSize.contains(":")) {
String[] valueSizes = valueSize.split(":");
if (valueSize.length() != 2) throw new RuntimeException("Invalid value size: " + valueSize);
minValueSize = Integer.parseInt(valueSizes[0]);
maxValueSize = Integer.parseInt(valueSizes[1]);
} else {
minValueSize = maxValueSize = Integer.parseInt(valueSize);
}
String datagen = cmd.getOptionValue(DATAGEN_KEY, "default").toLowerCase();
if ("default".equals(datagen)) {
dataGen = new MultiThreadedAction.DefaultDataGenerator(
minValueSize, maxValueSize, 1, 1, new byte[][] { COLUMN_FAMILY });
} else if ("sequential".equals(datagen)) {
int shards = Integer.parseInt(cmd.getOptionValue(SEQ_SHARDS_PER_SERVER_KEY, "1"));
dataGen = new SeqShardedDataGenerator(minValueSize, maxValueSize, shards);
} else {
throw new RuntimeException("Unknown " + DATAGEN_KEY + ": " + datagen);
}
iterationCount = Integer.parseInt(cmd.getOptionValue(ITERATIONS_KEY, "1"));
preloadKeys = Long.parseLong(cmd.getOptionValue(PRELOAD_COUNT_KEY, "1000000"));
writeKeys = Long.parseLong(cmd.getOptionValue(WRITE_COUNT_KEY, "1000000"));
writeThreads = Integer.parseInt(cmd.getOptionValue(WRITE_THREADS_KEY, "10"));
readThreads = Integer.parseInt(cmd.getOptionValue(READ_THREADS_KEY, "20"));
initialStripeCount = getLongOrNull(cmd, INITIAL_STRIPE_COUNT_KEY);
splitSize = getLongOrNull(cmd, SPLIT_SIZE_KEY);
splitParts = getLongOrNull(cmd, SPLIT_PARTS_KEY);
}
示例9: parseCommandLine
import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
/**
* Parses the command line and returns a corresponding BOQA object.
*
* @param args
*/
public static void parseCommandLine(String[] args)
{
Options opt = new Options();
opt.addOption("o", "ontology", true, "Path or URL to the ontology file.");
opt.addOption("a", "annotations", true, "Path or URL to files containing annotations.");
opt.addOption("p", "patient", true, "Path to directory with patients");
opt.addOption("d", "out", true, "Path to output directory");
opt.addOption("h", "help", false, "Shows this help");
try {
GnuParser parser = new GnuParser();
CommandLine cl;
cl = parser.parse(opt, args);
if (cl.hasOption('h')) {
HelpFormatter f = new HelpFormatter();
f.printHelp(BOQABenchmark.class.getName(), opt);
System.exit(0);
}
ontologyPath = cl.getOptionValue('o', ontologyPath); //so much nicer than C
annotationPath = cl.getOptionValue('a', annotationPath);
patientPath = cl.getOptionValue('p');
outPath = cl.getOptionValue('d');
} catch (ParseException e) {
logger.error("Failed to parse commandline: " + e.getLocalizedMessage());
System.exit(1);
}
}
示例10: processOptions
import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
@Override
protected void processOptions(CommandLine cmd) {
type = cmd.getOptionValue("type");
file = cmd.getOptionValue("file");
tablename = cmd.getOptionValue("table");
snapshotName = cmd.getOptionValue("snapshot");
restoreDir = cmd.getOptionValue("restoredir");
caching = cmd.getOptionValue("caching");
}
示例11: parseCommandLine
import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
private static void parseCommandLine(String[] args) {
Options options = new Options();
Option input = new Option("n", "timed-iterations", true, "number of iterations of timing loop");
input.setRequired(false);
options.addOption(input);
Option output = new Option("w", "warmup-iterations", true, "number of warm-up iterations before timing loop");
output.setRequired(false);
options.addOption(output);
Option hourly = new Option("h", "hourly", false, "whether to use hourly data");
hourly.setRequired(false);
options.addOption(hourly);
CommandLineParser parser = new DefaultParser();
HelpFormatter formatter = new HelpFormatter();
CommandLine cmd;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
System.out.println(e.getMessage());
formatter.printHelp("StlPerfTest", options);
System.exit(1);
return;
}
if (cmd.hasOption("hourly")) {
System.out.println("Running hourly stress test");
fRunCo2 = false;
fTimedIterations = 200;
fWarmupIterations = 30;
} else {
System.out.println("Running CO2 test");
fTimedIterations = 2000;
fWarmupIterations = 30;
}
String nStr = cmd.getOptionValue("number");
if (nStr != null)
fTimedIterations = Integer.parseInt(nStr);
String wStr = cmd.getOptionValue("warmup-iterations");
if (wStr != null)
fWarmupIterations = Integer.parseInt(wStr);
}
示例12: getVal
import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
private static String getVal(CommandLine command, String swtch) {
String optionValue = command.getOptionValue(swtch);
if (optionValue == null) {
return null;
} else {
return optionValue.trim();
}
}
示例13: main
import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
public static void main(String[] args) throws UnknownHostException {
CommandLine line = initializeAndParseCommandLineOptions(args);
String uri = line.getOptionValue("c");
final OplogAnalyzer analyzer = new OplogAnalyzer(uri);
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
analyzer.stop();
}
}));
analyzer.process();
analyzer.report();
}
示例14: main
import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// create the parser
CommandLineParser parser = new DefaultParser();
CommandLine line = parser.parse(getOptions(), args);
// files directory
String directory = line.getOptionValue("directory", "hkex/");
// config file
String config = line.getOptionValue("config", "config/tracker.properties");
// init scheduler
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler scheduler = sf.getScheduler();
// define job instance
JobDetail job = newJob(TrackerJob.class)
.withIdentity("job", "group")
.usingJobData("directory", directory)
.usingJobData("config", config)
.build();
// define trigger instance
Trigger trigger = newTrigger()
.withIdentity("trigger", "group")
.startNow()
.withSchedule(dailyAtHourAndMinute(8, 30)) // fire every day at 8:30
.build();
// schedule the job with the trigger
scheduler.scheduleJob(job, trigger);
// start scheduler
scheduler.start();
}
示例15: main
import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
CommandLineParser parser = new DefaultParser();
// create the Options
Options options = new Options();
options.addOption(Option.builder("f")
.required(true).hasArg()
.longOpt("extra_action_file")
.desc("bazel extra action protobuf file")
.build());
options.addOption(Option.builder("c")
.required(true).hasArg()
.longOpt("cpplint_file")
.desc("Executable cpplint file to invoke")
.build());
try {
// parse the command line arguments
CommandLine line = parser.parse(options, args);
String extraActionFile = line.getOptionValue("f");
String cpplintFile = line.getOptionValue("c");
Collection<String> sourceFiles = getSourceFiles(extraActionFile);
if (sourceFiles.size() == 0) {
LOG.fine("No cpp files found by checkstyle");
return;
}
LOG.fine(sourceFiles.size() + " cpp files found by checkstyle");
// Create and run the command
List<String> commandBuilder = new ArrayList<>();
commandBuilder.add(cpplintFile);
commandBuilder.add("--linelength=100");
// TODO: https://github.com/twitter/heron/issues/466,
// Remove "runtime/references" when we fix all non-const references in our codebase.
// TODO: https://github.com/twitter/heron/issues/467,
// Remove "runtime/threadsafe_fn" when we fix all non-threadsafe libc functions
commandBuilder.add("--filter=-build/header_guard,-runtime/references,-runtime/threadsafe_fn");
commandBuilder.addAll(sourceFiles);
runLinter(commandBuilder);
} catch (ParseException exp) {
LOG.severe(String.format("Invalid input to %s: %s", CLASSNAME, exp.getMessage()));
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java " + CLASSNAME, options);
}
}