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


Java GnuParser類代碼示例

本文整理匯總了Java中org.apache.commons.cli.GnuParser的典型用法代碼示例。如果您正苦於以下問題:Java GnuParser類的具體用法?Java GnuParser怎麽用?Java GnuParser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GnuParser類屬於org.apache.commons.cli包,在下文中一共展示了GnuParser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.apache.commons.cli.GnuParser; //導入依賴的package包/類
/**
 * Main method.
 * 
 * @param args
 * @throws IOException
 * @throws ParseException
 */
public static void main(String[] args) throws Exception {
	java.util.logging.Logger l = java.util.logging.Logger.getLogger("org.glassfish.grizzly.http.server.HttpHandler");
	l.setLevel(java.util.logging.Level.FINE);
	l.setUseParentHandlers(false);
	java.util.logging.ConsoleHandler ch = new java.util.logging.ConsoleHandler();
	ch.setLevel(java.util.logging.Level.ALL);
	l.addHandler(ch);

	CommandLineParser parser = new GnuParser();
	Options options = new Options();
	options.addOption("h", "host", true, "Server hostname.");
	options.addOption("p", "port", true, "TCP port to listen.");
	options.addOption("s", "storage_path", true, "Storage path.");
	options.addOption("w", "wat_gcube_token", true, "WAT gcube authentication token");
	CommandLine line = parser.parse(options, args);

	String serverUri = String.format("http://%s:%d/smaph", line.getOptionValue("host", "localhost"),
	        Integer.parseInt(line.getOptionValue("port", "8080")));
	Path storage = Paths.get(line.getOptionValue("storage_path"));
	startServer(serverUri, storage, line.getOptionValue("wat_gcube_token"));
}
 
開發者ID:marcocor,項目名稱:smaph,代碼行數:29,代碼來源:ServerMain.java

示例2: MyOptions

import org.apache.commons.cli.GnuParser; //導入依賴的package包/類
public MyOptions(String[] args) {
  seed = System.nanoTime();

  try {
    Options opts = buildOptions();
    CommandLineParser parser = new GnuParser();
    CommandLine line = parser.parse(opts, args, true);
    processOptions(line, opts);
    validateOptions();
  }
  catch (ParseException e) {
    System.out.println(e.getMessage());
    System.out.println("Try \"--help\" option for details.");
    setStopProceed();
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:17,代碼來源:TestTFileSeek.java

示例3: handleNetezzaImportExtraArgs

import org.apache.commons.cli.GnuParser; //導入依賴的package包/類
private void handleNetezzaImportExtraArgs(ImportJobContext context)
    throws ParseException {

  SqoopOptions opts = context.getOptions();
  Configuration conf = opts.getConf();

  String[] extraArgs = opts.getExtraArgs();


  conf.setBoolean(NETEZZA_DATASLICE_ALIGNED_ACCESS_OPT, false);

  if (extraArgs != null && extraArgs.length > 0
      && ConfigurationHelper.getConfNumMaps(conf) > 1) {
    RelatedOptions netezzaOpts = getNetezzaExtraOpts();
    CommandLine cmdLine = new GnuParser().parse(netezzaOpts, extraArgs, true);
    if (cmdLine.hasOption(NETEZZA_DATASLICE_ALIGNED_ACCESS_LONG_ARG)) {
      conf.setBoolean(NETEZZA_DATASLICE_ALIGNED_ACCESS_OPT, true);
      context.setInputFormat(NetezzaDataDrivenDBInputFormat.class);
    }
  }

}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:23,代碼來源:NetezzaManager.java

示例4: main

import org.apache.commons.cli.GnuParser; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
  CommandLine cmd = new GnuParser().parse(opts, args);
  if (cmd.hasOption("help")) {
    new HelpFormatter().printHelp("Usage: hbgen [OPTIONS]", opts);
    return;
  }
  // defaults
  Class<?> specClass = HamletSpec.class;
  Class<?> implClass = HamletImpl.class;
  String outputClass = "HamletTmp";
  String outputPackage = implClass.getPackage().getName();
  if (cmd.hasOption("spec-class")) {
    specClass = Class.forName(cmd.getOptionValue("spec-class"));
  }
  if (cmd.hasOption("impl-class")) {
    implClass = Class.forName(cmd.getOptionValue("impl-class"));
  }
  if (cmd.hasOption("output-class")) {
    outputClass = cmd.getOptionValue("output-class");
  }
  if (cmd.hasOption("output-package")) {
    outputPackage = cmd.getOptionValue("output-package");
  }
  new HamletGen().generate(specClass, implClass, outputClass, outputPackage);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:HamletGen.java

示例5: main

import org.apache.commons.cli.GnuParser; //導入依賴的package包/類
public static void main(String[] argv) throws Exception {
  CommandLine cliParser = new GnuParser().parse(opts, argv);
  if (cliParser.hasOption("put")) {
    String path = cliParser.getOptionValue("put");
    if (path != null && path.length() > 0) {
      if (cliParser.hasOption(ENTITY_DATA_TYPE)) {
        putTimelineDataInJSONFile(path, ENTITY_DATA_TYPE);
        return;
      } else if (cliParser.hasOption(DOMAIN_DATA_TYPE)) {
        putTimelineDataInJSONFile(path, DOMAIN_DATA_TYPE);
        return;
      }
    }
  }
  printUsage();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:TimelineClientImpl.java

示例6: utility

import org.apache.commons.cli.GnuParser; //導入依賴的package包/類
private void utility(String... args) throws Exception {

        final Options options = new Options();
        options.addOption("sp", true, "sourcePath");
        options.addOption("tp", true, "targetPath");
        options.addOption("threshold", true, "thresholdInBytes");

        final CommandLineParser commandLineParser = new GnuParser();
        final CommandLine commandLine = commandLineParser.parse(options, args);
        log.info("source Path " + commandLine.getOptionValue("sp"));
        log.info("Target Path " + commandLine.getOptionValue("tp"));
        log.info("Threshold " + commandLine.getOptionValue("threshold"));

        final Map<String, String> optionsMap = new HashMap<String, String>();
        optionsMap.put("sourcePath", commandLine.getOptionValue("sp"));
        optionsMap.put("targetPath", commandLine.getOptionValue("tp"));
        optionsMap.put("thresholdInBytes", commandLine.getOptionValue("threshold"));

        final CompactionManager compactionManager = CompactionManagerFactory.create(optionsMap);
        final CompactionResponse compactionResponse = compactionManager.compact();
        log.info("Compaction Response Success {}", compactionResponse.isSuccessful());
        log.info("Compaction Response FileType {}", compactionResponse.getTargetFileType());
        log.info("Compaction Response Target Path {}", compactionResponse.getTargetPath());
    }
 
開發者ID:ExpediaInceCommercePlatform,項目名稱:dataSqueeze,代碼行數:25,代碼來源:Utility.java

示例7: main

import org.apache.commons.cli.GnuParser; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
  CommandLineParser parser = new GnuParser();
  Options options = createWebAppOptions();
  CommandLine commandLine = null;
  HelpFormatter formatter = new HelpFormatter();
  try {
    commandLine = parser.parse(options, args);
  } catch (Exception e) {
    formatter.printHelp("NutchUiServer", options, true);
    StringUtils.stringifyException(e);
  }

  if (commandLine.hasOption("help")) {
    formatter.printHelp("NutchUiServer", options, true);
    return;
  }
  if (commandLine.hasOption(CMD_PORT)) {
    port = Integer.parseInt(commandLine.getOptionValue(CMD_PORT));
  }
  startServer();
}
 
開發者ID:jorcox,項目名稱:GeoCrawler,代碼行數:22,代碼來源:NutchUiServer.java

示例8: main

import org.apache.commons.cli.GnuParser; //導入依賴的package包/類
public static void main(String args[]) throws IOException, ParseException {
    Options options = new Options();
    options.addOption("i","insdist",false,"print insert size distribution");
    options.addOption("s","stats",false,"print mapping stats");
    options.addOption("l","readlen",false,"read length");
    options.addOption("c","readcount",false,"read count");
    options.addOption("bt2",false,"input is from bowtie2");
    options.addOption("bt1",false,"input is from bowtie1 (tested for --best --strata -m 1)");
    CommandLineParser parser = new GnuParser();
    CommandLine cl = parser.parse( options, args, false );       
    
    SAMStats s = new SAMStats(cl.hasOption("bt1"), cl.hasOption("bt2"));
    if(cl.hasOption("insdist"))
    	s.printInsertDistrib();
    if(cl.hasOption("stats"))
    	s.printStats();
    if(cl.hasOption("readlen"))
    	s.printReadLength();
    if(cl.hasOption("readcount"))
    	s.printReadCount();
}
 
開發者ID:seqcode,項目名稱:seqcode-core,代碼行數:22,代碼來源:SAMStats.java

示例9: init

import org.apache.commons.cli.GnuParser; //導入依賴的package包/類
@Override
public boolean init(String[] args) throws ParseException {
  CommandLine cliParser = new GnuParser().parse(opts, args);

  if (!cliParser.hasOption("jar")) {
    throw new IllegalArgumentException("No jar file specified for application master");
  }
  appMasterJar = cliParser.getOptionValue("jar");

  if (!cliParser.hasOption("configFile")) {
    throw new IllegalArgumentException("No config file specified");
  }
  configFile = cliParser.getOptionValue("configFile");
  String configFileContent = readConfigFileContent(configFile);
  yacopConfig = parseConfigFile(configFileContent);

  if (yacopConfig == null) {
    return false;
  }
  return true;
}
 
開發者ID:intel-hadoop,項目名稱:yacop,代碼行數:22,代碼來源:ActionSubmitApp.java

示例10: init

import org.apache.commons.cli.GnuParser; //導入依賴的package包/類
@Override
public boolean init(String[] args) throws ParseException {
  CommandLine cliParser = new GnuParser().parse(opts, args);

  if (!cliParser.hasOption("applicationId")) {
    throw new IllegalArgumentException("no application id specified");
  }
  applicationId = cliParser.getOptionValue("applicationId");

  if (!cliParser.hasOption("containerHost")) {
    throw new IllegalArgumentException("no container host specified");
  }
  containerHost = cliParser.getOptionValue("containerHost");

  if (!cliParser.hasOption("containerId")) {
    throw new IllegalArgumentException("no container id specified");
  }
  containerId = cliParser.getOptionValue("containerId");

  if (!cliParser.hasOption("containerPort")) {
    throw new IllegalArgumentException("no container port specified");
  }
  containerPort = cliParser.getOptionValue("containerPort");

  return true;
}
 
開發者ID:intel-hadoop,項目名稱:yacop,代碼行數:27,代碼來源:ActionDoPortMapping.java

示例11: 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

示例12: 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

示例13: runMain

import org.apache.commons.cli.GnuParser; //導入依賴的package包/類
/**
 * Non-static version of main so that we can define anonymous local classes to override or extend
 * the above.
 * @param args a String array of input options
 */
public void runMain(String[] args) {
  Options o = this.getCliOptions();
  try {
    new GnuParser().parse(o, args);
  } catch (ParseException pe) {
    // The message from pe is ugly, so we omit it.
    System.err.println("Error parsing command line");
    new HelpFormatter().printHelp(this.getClassName(), o);
    System.exit(1);
  }

  try {
    float ratio = 0.8f;
    if (this.oratio.getValue() != null) {
      ratio = Float.parseFloat(this.oratio.getValue());
    }
    this.runSubsampler(this.otest.getValues(), 12, 20, ratio);
  } catch (Exception e) {
    e.printStackTrace();
    System.exit(1);
  }
}
 
開發者ID:apache,項目名稱:incubator-joshua,代碼行數:28,代碼來源:SubsamplerCLI.java

示例14: parseArgs

import org.apache.commons.cli.GnuParser; //導入依賴的package包/類
/**
 * Parses the arguments. The valid arguments are:
 *  --help or -h : prints out help message for this main class.
 *  --json or -j : the JSON file.
 * @param args the arguments passed in as options.
 */
@Override
public void parseArgs(String [] args) throws AdeUsageException{
    Options options = new Options();
    buildOptions(options);        
    CommandLineParser parser = new GnuParser();
    CommandLine line = parseLine(parser,options,args);
    
    if (line.hasOption('h')) {
        new HelpFormatter().printHelp(this.getClass().getSimpleName(), options);
        System.exit(0);
    }
    
    if (line.hasOption('j')){
        String jsonFile = line.getOptionValue("j");
        inputJSONFile = new File(jsonFile);
        validateFile(inputJSONFile);
    } else{
        new HelpFormatter().printHelp(this.getClass().getSimpleName(), options);
        throw new AdeUsageException("Must specify a JSON file path using the -j option.");
    }
}
 
開發者ID:openmainframeproject,項目名稱:ade,代碼行數:28,代碼來源:UpdateGroups.java

示例15: 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


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