當前位置: 首頁>>代碼示例>>Java>>正文


Java GnuParser.parse方法代碼示例

本文整理匯總了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"));
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:26,代碼來源:Verify.java

示例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"));
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:24,代碼來源:Generator.java

示例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;
}
 
開發者ID:testmycode,項目名稱:tmc-cli,代碼行數:23,代碼來源:AbstractCommand.java

示例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();
}
 
開發者ID:jyang,項目名稱:google-feedserver,代碼行數:26,代碼來源:CommonsCliHelper.java

示例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();
}
 
開發者ID:jyang,項目名稱:google-feedserver,代碼行數:28,代碼來源:BeanCliHelper.java

示例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);
    }

}
 
開發者ID:johntiger1,項目名稱:boqa,代碼行數:37,代碼來源:BOQABenchmark.java

示例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;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:56,代碼來源:IntegrationTestBigLinkedList.java

示例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() );
  }
}
 
開發者ID:casific,項目名稱:murmur,代碼行數:73,代碼來源:ProximitySimulation.java

示例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;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:54,代碼來源:Walker.java

示例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;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:74,代碼來源:Loop.java

示例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;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:49,代碼來源:Print.java

示例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" );
    }
}
 
開發者ID:cchabanois,項目名稱:mesfavoris,代碼行數:57,代碼來源:BugsTest.java

示例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;
}
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:55,代碼來源:IntegrationTestBigLinkedList.java

示例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;
}
 
開發者ID:tenggyut,項目名稱:HIndex,代碼行數:56,代碼來源:IntegrationTestBigLinkedList.java


注:本文中的org.apache.commons.cli.GnuParser.parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。