本文整理汇总了Java中org.apache.commons.cli.GnuParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java GnuParser.parse方法的具体用法?Java GnuParser.parse怎么用?Java GnuParser.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.cli.GnuParser
的用法示例。
在下文中一共展示了GnuParser.parse方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.apache.commons.cli.GnuParser; //导入方法依赖的package包/类
@Override
public int run(String[] args) throws Exception {
Options options = new Options();
options.addOption("c", "concurrent", false, "run concurrently with generation");
GnuParser parser = new GnuParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
if (cmd.getArgs().length != 2) {
throw new ParseException("Did not see expected # of arguments, saw " + cmd.getArgs().length);
}
} catch (ParseException e) {
LOG.error("Failed to parse command line {}", e.getMessage());
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(getClass().getSimpleName() + " <output dir> <num reducers>", options);
System.exit(-1);
}
String outputDir = cmd.getArgs()[0];
int numReducers = Integer.parseInt(cmd.getArgs()[1]);
return run(outputDir, numReducers, cmd.hasOption("c"));
}
示例2: run
import org.apache.commons.cli.GnuParser; //导入方法依赖的package包/类
@Override
public int run(String[] args) throws Exception {
Options options = new Options();
options.addOption("c", "concurrent", false, "update secondary table with information that allows verification to run concurrently");
GnuParser parser = new GnuParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
if (cmd.getArgs().length != 2) {
throw new ParseException("Did not see expected # of arguments, saw " + cmd.getArgs().length);
}
} catch (ParseException e) {
LOG.error("Failed to parse command line {}", e.getMessage());
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(getClass().getSimpleName() + " <num mappers> <num nodes per map>", options);
System.exit(-1);
}
int numMappers = Integer.parseInt(cmd.getArgs()[0]);
long numNodes = Long.parseLong(cmd.getArgs()[1]);
return run(numMappers, numNodes, cmd.hasOption("c"));
}
示例3: parseArgs
import org.apache.commons.cli.GnuParser; //导入方法依赖的package包/类
protected CommandLine parseArgs(CliContext context, String[] stringArgs) {
GnuParser parser = new GnuParser();
CommandLine args;
Options options = getOptions();
Io io = context.getIo();
try {
args = parser.parse(options, stringArgs);
} catch (ParseException e) {
logger.warn("Invalid command line arguments.", e);
io.errorln("Invalid command line arguments.");
io.errorln(e.getMessage());
return null;
}
if (args.hasOption("h")) {
printHelp(context);
return null;
}
return args;
}
示例4: parse
import org.apache.commons.cli.GnuParser; //导入方法依赖的package包/类
/**
* With provided command line string, populates all registered classes _FLAG
* fields with their command-line values.
*
* @param args command-line.
*/
public void parse(String[] args) {
options = createOptions();
GnuParser parser = new GnuParser();
try {
flags = parser.parse(options, args);
} catch (ParseException e) {
usage();
throw new RuntimeException(e);
}
/*
* Print help text and exit.
*/
if (flags.hasOption("help")) {
usage();
System.exit(0);
}
populateClasses();
}
示例5: parse
import org.apache.commons.cli.GnuParser; //导入方法依赖的package包/类
/**
* With provided command line string, populates all registered classes with
* decorated fields with their config file then command-line values.
*
* @param args command-line.
*/
public void parse(String[] args) throws ConfigurationBeanException, ParseException,
java.text.ParseException {
options = createOptions();
GnuParser parser = new GnuParser();
try {
flags = parser.parse(options, args);
} catch (ParseException e) {
usage();
throw new ConfigurationBeanException("Command line parse error.", e);
}
/*
* Print help text and exit.
*/
if (flags.hasOption("help")) {
usage();
System.exit(0);
}
populateBeansFromConfigFile();
populateBeansFromCommandLine();
}
示例6: parseCommandLine
import org.apache.commons.cli.GnuParser; //导入方法依赖的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);
}
}
示例7: run
import org.apache.commons.cli.GnuParser; //导入方法依赖的package包/类
@Override
public int run(String[] args) throws Exception {
Options options = new Options();
options.addOption("s", "start", true, "start key");
options.addOption("e", "end", true, "end key");
options.addOption("l", "limit", true, "number to print");
GnuParser parser = new GnuParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
if (cmd.getArgs().length != 0) {
throw new ParseException("Command takes no arguments");
}
} catch (ParseException e) {
System.err.println("Failed to parse command line " + e.getMessage());
System.err.println();
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(getClass().getSimpleName(), options);
System.exit(-1);
}
Table table = new HTable(getConf(), getTableName(getConf()));
Scan scan = new Scan();
scan.setBatch(10000);
if (cmd.hasOption("s"))
scan.setStartRow(Bytes.toBytesBinary(cmd.getOptionValue("s")));
if (cmd.hasOption("e"))
scan.setStopRow(Bytes.toBytesBinary(cmd.getOptionValue("e")));
int limit = 0;
if (cmd.hasOption("l"))
limit = Integer.parseInt(cmd.getOptionValue("l"));
else
limit = 100;
ResultScanner scanner = table.getScanner(scan);
CINode node = new CINode();
Result result = scanner.next();
int count = 0;
while (result != null && count++ < limit) {
node = getCINode(result, node);
System.out.printf("%s:%s:%012d:%s\n", Bytes.toStringBinary(node.key),
Bytes.toStringBinary(node.prev), node.count, node.client);
result = scanner.next();
}
scanner.close();
table.close();
return 0;
}
示例8: parseOptions
import org.apache.commons.cli.GnuParser; //导入方法依赖的package包/类
/**
* Parse the command line options.
*
* @param args The input arguments from the command line.
* @param options The pre-defined options that can be set.
*/
public static void parseOptions(String[] args, Options options) {
// create the parser
GnuParser parser = new GnuParser();
try {
// parse the command line arguments
CommandLine line = parser.parse( options, args );
// has the number of nodes argument been passed?
NUMBER_OF_PEOPLE = parseIntegerArg( line, "nn" , NUMBER_OF_PEOPLE );
if (NUMBER_OF_PEOPLE < 1) {
// automatically generate the help statement
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "ProximitySimulation", options, true );
System.err.println( "\n\nYou must enter a valid number of people." );
return;
}
// Number of adversaries (default=0)
NUMBER_OF_ADVERSARIES = parseIntegerArg( line, "na" , NUMBER_OF_ADVERSARIES );
NUMBER_OF_ADVERSARIES = Math.min( NUMBER_OF_PEOPLE, NUMBER_OF_ADVERSARIES);
// author popularity (default = random)
if( line.hasOption( "author" ) ) {
// initialise the member variable
String popularity = line.getOptionValue( "author" );
if (popularity.equals("random")) {
messageAuthor = RANDOM_AUTHOR;
} else if (popularity.equals("popular")) {
messageAuthor = POPULAR_AUTHOR;
popularAuthor = true;
} else if (popularity.equals("unpopular")) {
messageAuthor = POPULAR_AUTHOR;
popularAuthor = false;
} else if (popularity.equals("adversarial")) {
messageAuthor = ADVERSARIAL_AUTHOR;
} else {
System.err.println("Not a valid popularity flag.");
}
}
// number of stationary jammers
NUMBER_OF_STATIC_JAMMERS = parseIntegerArg( line, "jamStationary" , NUMBER_OF_STATIC_JAMMERS );
if (NUMBER_OF_STATIC_JAMMERS > 0) {
staticJamming = true;
}
// stationary jammer optimality
if( line.hasOption( "jamOpt" ) ) {
staticJammingOptimal = true;
}
//Mobile jammers
NUMBER_OF_MOBILE_JAMMERS = parseIntegerArg( line, "jamMobile" , NUMBER_OF_MOBILE_JAMMERS );
if (NUMBER_OF_MOBILE_JAMMERS > 0) {
mobileJamming = true;
}
//Jammers' radius
JAMMING_RADIUS = parseDoubleArg( line, "radius" , JAMMING_RADIUS );
}
catch( Exception exp ) {
// oops, something went wrong
System.err.println( "Parsing failed. Reason: " + exp.getMessage() );
}
}
示例9: run
import org.apache.commons.cli.GnuParser; //导入方法依赖的package包/类
public int run(String[] args) throws IOException {
Options options = new Options();
options.addOption("n", "num", true, "number of queries");
GnuParser parser = new GnuParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
if (cmd.getArgs().length != 0) {
throw new ParseException("Command takes no arguments");
}
} catch (ParseException e) {
LOG.error("Failed to parse command line {}", e.getMessage());
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(getClass().getSimpleName(), options);
System.exit(-1);
}
long maxQueries = Long.MAX_VALUE;
if (cmd.hasOption('n')) {
maxQueries = Long.parseLong(cmd.getOptionValue("n"));
}
DataStore<Long,CINode> store = DataStoreFactory.getDataStore(Long.class, CINode.class, new Configuration());
Random rand = new Random();
long numQueries = 0;
while (numQueries < maxQueries) {
CINode node = findStartNode(rand, store);
numQueries++;
while (node != null && node.getPrev() >= 0 && numQueries < maxQueries) {
long prev = node.getPrev();
long t1 = System.currentTimeMillis();
node = store.get(prev, PREV_FIELD);
long t2 = System.currentTimeMillis();
LOG.info("CQ %d %016x \n {}", new Object [] {t2 - t1, prev});
numQueries++;
t1 = System.currentTimeMillis();
node = store.get(prev, PREV_FIELD);
t2 = System.currentTimeMillis();
LOG.info("HQ %d %016x \n {}", new Object [] {t2 - t1, prev});
numQueries++;
}
}
store.close();
return 0;
}
示例10: run
import org.apache.commons.cli.GnuParser; //导入方法依赖的package包/类
@Override
public int run(String[] args) throws Exception {
Options options = new Options();
options.addOption("c", "concurrent", false, "run generation and verification and concurrently");
GnuParser parser = new GnuParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
if (cmd.getArgs().length != 5) {
throw new ParseException("Did not see expected # of arguments, saw " + cmd.getArgs().length);
}
} catch (ParseException e) {
LOG.error("Failed to parse command line {}", e.getMessage());
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(getClass().getSimpleName() + " <num iterations> <num mappers> <num nodes per mapper> <output dir> <num reducers>", options);
System.exit(-1);
}
LOG.info("Running Loop with args:" + Arrays.deepToString(cmd.getArgs()));
boolean concurrent = cmd.hasOption("c");
int numIterations = Integer.parseInt(cmd.getArgs()[0]);
int numMappers = Integer.parseInt(cmd.getArgs()[1]);
long numNodes = Long.parseLong(cmd.getArgs()[2]);
String outputDir = cmd.getArgs()[3];
int numReducers = Integer.parseInt(cmd.getArgs()[4]);
if (numNodes % Generator.WRAP != 0) {
throw new RuntimeException("Number of node per mapper is not a multiple of " + String.format(Locale.getDefault(), "%,d", Generator.WRAP));
}
long expectedNumNodes = 0;
if (numIterations < 0) {
numIterations = Integer.MAX_VALUE; //run indefinitely (kind of)
}
Verify verify = null;
long verifyNodes = 0;
for (int i=0; i < numIterations; i++) {
LOG.info("Starting iteration = {}", i);
runGenerator(numMappers, numNodes, concurrent);
expectedNumNodes += numMappers * numNodes;
if (concurrent) {
if (verify != null) {
if (verify.isComplete()) {
checkSuccess(verify, verifyNodes);
verify = startVerify(outputDir, numReducers, true);
verifyNodes = expectedNumNodes;
}
} else {
verify = startVerify(outputDir, numReducers, true);
verifyNodes = expectedNumNodes;
}
} else {
runVerify(outputDir, numReducers, expectedNumNodes);
}
}
if (verify != null) {
verify.waitForCompletion();
checkSuccess(verify, verifyNodes);
if (verifyNodes != expectedNumNodes)
runVerify(outputDir, numReducers, expectedNumNodes);
}
return 0;
}
示例11: run
import org.apache.commons.cli.GnuParser; //导入方法依赖的package包/类
public int run(String[] args) throws Exception {
Options options = new Options();
options.addOption("s", "start", true, "start key");
options.addOption("e", "end", true, "end key");
options.addOption("l", "limit", true, "number to print");
GnuParser parser = new GnuParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
if (cmd.getArgs().length != 0) {
throw new ParseException("Command takes no arguments");
}
} catch (ParseException e) {
LOG.error("Failed to parse command line {}", e.getMessage());
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(getClass().getSimpleName(), options);
System.exit(-1);
}
DataStore<Long,CINode> store = DataStoreFactory.getDataStore(Long.class, CINode.class, new Configuration());
Query<Long,CINode> query = store.newQuery();
if (cmd.hasOption("s"))
query.setStartKey(new BigInteger(cmd.getOptionValue("s"), 16).longValue());
if (cmd.hasOption("e"))
query.setEndKey(new BigInteger(cmd.getOptionValue("e"), 16).longValue());
if (cmd.hasOption("l"))
query.setLimit(Integer.parseInt(cmd.getOptionValue("l")));
else
query.setLimit(100);
Result<Long,CINode> rs = store.execute(query);
while (rs.next()) {
CINode node = rs.get();
LOG.info("%016x:%016x:%012d:%s\n {} {} {} {}", new Object[] {rs.getKey(),
node.getPrev(), node.getCount(), node.getClient()});
}
store.close();
return 0;
}
示例12: test12210
import org.apache.commons.cli.GnuParser; //导入方法依赖的package包/类
@Test
public void test12210() throws Exception
{
// create the main options object which will handle the first parameter
Options mainOptions = new Options();
// There can be 2 main exclusive options: -exec|-rep
// Therefore, place them in an option group
String[] argv = new String[] { "-exec", "-exec_opt1", "-exec_opt2" };
OptionGroup grp = new OptionGroup();
grp.addOption(new Option("exec",false,"description for this option"));
grp.addOption(new Option("rep",false,"description for this option"));
mainOptions.addOptionGroup(grp);
// for the exec option, there are 2 options...
Options execOptions = new Options();
execOptions.addOption("exec_opt1", false, " desc");
execOptions.addOption("exec_opt2", false, " desc");
// similarly, for rep there are 2 options...
Options repOptions = new Options();
repOptions.addOption("repopto", false, "desc");
repOptions.addOption("repoptt", false, "desc");
// create the parser
GnuParser parser = new GnuParser();
// finally, parse the arguments:
// first parse the main options to see what the user has specified
// We set stopAtNonOption to true so it does not touch the remaining
// options
CommandLine cmd = parser.parse(mainOptions,argv,true);
// get the remaining options...
argv = cmd.getArgs();
if(cmd.hasOption("exec"))
{
cmd = parser.parse(execOptions,argv,false);
// process the exec_op1 and exec_opt2...
assertTrue( cmd.hasOption("exec_opt1") );
assertTrue( cmd.hasOption("exec_opt2") );
}
else if(cmd.hasOption("rep"))
{
cmd = parser.parse(repOptions,argv,false);
// process the rep_op1 and rep_opt2...
}
else {
fail( "exec option not found" );
}
}
示例13: run
import org.apache.commons.cli.GnuParser; //导入方法依赖的package包/类
public int run(String[] args) throws Exception {
Options options = new Options();
options.addOption("s", "start", true, "start key");
options.addOption("e", "end", true, "end key");
options.addOption("l", "limit", true, "number to print");
GnuParser parser = new GnuParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
if (cmd.getArgs().length != 0) {
throw new ParseException("Command takes no arguments");
}
} catch (ParseException e) {
System.err.println("Failed to parse command line " + e.getMessage());
System.err.println();
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(getClass().getSimpleName(), options);
System.exit(-1);
}
HTable table = new HTable(getConf(), getTableName(getConf()));
Scan scan = new Scan();
scan.setBatch(10000);
if (cmd.hasOption("s"))
scan.setStartRow(Bytes.toBytesBinary(cmd.getOptionValue("s")));
if (cmd.hasOption("e"))
scan.setStopRow(Bytes.toBytesBinary(cmd.getOptionValue("e")));
int limit = 0;
if (cmd.hasOption("l"))
limit = Integer.parseInt(cmd.getOptionValue("l"));
else
limit = 100;
ResultScanner scanner = table.getScanner(scan);
CINode node = new CINode();
Result result = scanner.next();
int count = 0;
while (result != null && count++ < limit) {
node = getCINode(result, node);
System.out.printf("%s:%s:%012d:%s\n", Bytes.toStringBinary(node.key),
Bytes.toStringBinary(node.prev), node.count, node.client);
result = scanner.next();
}
scanner.close();
table.close();
return 0;
}
示例14: run
import org.apache.commons.cli.GnuParser; //导入方法依赖的package包/类
@Override
public int run(String[] args) throws Exception {
Options options = new Options();
options.addOption("s", "start", true, "start key");
options.addOption("e", "end", true, "end key");
options.addOption("l", "limit", true, "number to print");
GnuParser parser = new GnuParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
if (cmd.getArgs().length != 0) {
throw new ParseException("Command takes no arguments");
}
} catch (ParseException e) {
System.err.println("Failed to parse command line " + e.getMessage());
System.err.println();
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(getClass().getSimpleName(), options);
System.exit(-1);
}
HTable table = new HTable(getConf(), getTableName(getConf()));
Scan scan = new Scan();
scan.setBatch(10000);
if (cmd.hasOption("s"))
scan.setStartRow(Bytes.toBytesBinary(cmd.getOptionValue("s")));
if (cmd.hasOption("e"))
scan.setStopRow(Bytes.toBytesBinary(cmd.getOptionValue("e")));
int limit = 0;
if (cmd.hasOption("l"))
limit = Integer.parseInt(cmd.getOptionValue("l"));
else
limit = 100;
ResultScanner scanner = table.getScanner(scan);
CINode node = new CINode();
Result result = scanner.next();
int count = 0;
while (result != null && count++ < limit) {
node = getCINode(result, node);
System.out.printf("%s:%s:%012d:%s\n", Bytes.toStringBinary(node.key),
Bytes.toStringBinary(node.prev), node.count, node.client);
result = scanner.next();
}
scanner.close();
table.close();
return 0;
}