Java Code Examples for org.apache.commons.cli.GnuParser#parse()
The following examples show how to use
org.apache.commons.cli.GnuParser#parse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetricsIngester.java From datawave with Apache License 2.0 | 6 votes |
private void _configure(String[] args) { GnuParser parser = new GnuParser(); CommandLine cmd; try { cmd = parser.parse(new MetricsOptions(), args); } catch (ParseException e) { log.warn("Could not parse command line options. Defaults from metrics.xml will be used.", e); return; } Configuration conf = getConf(); URL metricsConfig = MetricsIngester.class.getClassLoader().getResource("metrics.xml"); if (metricsConfig != null) { conf.addResource(metricsConfig); } for (Option opt : cmd.getOptions()) { conf.set(MetricsConfig.MTX + opt.getOpt(), opt.getValue()); } }
Example 2
Source File: AbstractCommand.java From tmc-cli with MIT License | 6 votes |
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; }
Example 3
Source File: S3mper.java From s3mper with Apache License 2.0 | 6 votes |
private void processSQS(String [] args) throws Exception { GnuParser parser = new GnuParser(); Options options = new Options(); CommandLine cmdline = parser.parse(options, args); SQS_CMD cmd = SQS_CMD.valueOf(cmdline.getArgs()[0].toUpperCase()); AlertJanitor janitor = new AlertJanitor(); janitor.initalize(PathUtil.S3N, new Configuration()); String queue = janitor.resolveQueueUrl(cmdline.getArgs()[1]); switch(cmd) { case LOG: janitor.writeLogs(queue, new Path(cmdline.getArgs()[2])); break; case PURGE: janitor.clearAll(queue); break; default: usage(); } }
Example 4
Source File: RunJobCli.java From submarine with Apache License 2.0 | 5 votes |
private void parseCommandLineAndGetRunJobParameters(String[] args) throws ParseException, IOException, YarnException { try { GnuParser parser = new GnuParser(); CommandLine cli = parser.parse(options, args); parametersHolder = createParametersHolder(cli); parametersHolder.updateParameters(clientContext); } catch (ParseException e) { LOG.error("Exception in parse: {}", e.getMessage()); printUsages(); throw e; } }
Example 5
Source File: ShowJobCli.java From submarine with Apache License 2.0 | 5 votes |
private void parseCommandLineAndGetShowJobParameters(String[] args) throws IOException, YarnException { // Do parsing GnuParser parser = new GnuParser(); CommandLine cli; try { cli = parser.parse(options, args); parametersHolder = ParametersHolder .createWithCmdLine(cli, Command.SHOW_JOB); parametersHolder.updateParameters(clientContext); } catch (ParseException e) { printUsages(); } }
Example 6
Source File: Migration.java From blueflood with Apache License 2.0 | 4 votes |
private static Map<String, Object> parseOptions(String[] args) { final GnuParser parser = new GnuParser(); final Map<String, Object> options = new HashMap<String, Object>(); try { final long now = System.currentTimeMillis(); CommandLine line = parser.parse(cliOptions, args); options.put(SRC, line.getOptionValue(SRC)); options.put(DST, line.getOptionValue(DST)); // default range is one year ago until now. options.put(FROM, line.hasOption(FROM) ? parseDateTime(line.getOptionValue(FROM)) : now-(365L*24L*60L*60L*1000L)); options.put(TO, line.hasOption(TO) ? parseDateTime(line.getOptionValue(TO)) : now); options.put(LIMIT, line.hasOption(LIMIT) ? Integer.parseInt(line.getOptionValue(LIMIT)) : Integer.MAX_VALUE); options.put(SKIP, line.hasOption(SKIP) ? Integer.parseInt(line.getOptionValue(SKIP)) : 0); options.put(BATCH_SIZE, line.hasOption(BATCH_SIZE) ? Integer.parseInt(line.getOptionValue(BATCH_SIZE)) : 100); // create a mapping of all cf names -> cf. // then determine which column family to process. Map<String, ColumnFamily<Locator, Long>> nameToCf = new HashMap<String, ColumnFamily<Locator, Long>>() {{ for (CassandraModel.MetricColumnFamily cf : CassandraModel.getMetricColumnFamilies()) { put(cf.getName(), cf); } }}; if (nameToCf.get(line.getOptionValue(COLUMN_FAMILY)) == null) { throw new ParseException("Invalid column family"); } CassandraModel.MetricColumnFamily columnFamily = (CassandraModel.MetricColumnFamily)nameToCf.get(line.getOptionValue(COLUMN_FAMILY)); options.put(COLUMN_FAMILY, columnFamily); options.put(TTL, line.hasOption(TTL) ? Integer.parseInt(line.getOptionValue(TTL)) : (int)(5 * columnFamily.getDefaultTTL().toSeconds())); options.put(READ_THREADS, line.hasOption(READ_THREADS) ? Integer.parseInt(line.getOptionValue(READ_THREADS)) : 1); options.put(WRITE_THREADS, line.hasOption(WRITE_THREADS) ? Integer.parseInt(line.getOptionValue(WRITE_THREADS)) : 1); options.put(VERIFY, line.hasOption(VERIFY)); options.put(DISCOVER, line.hasOption(DISCOVER) ? NodeDiscoveryType.RING_DESCRIBE : NodeDiscoveryType.NONE); options.put(RATE, line.hasOption(RATE) ? Integer.parseInt(line.getOptionValue(RATE)) : 500); } catch (ParseException ex) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("bf-migrate", cliOptions); System.exit(-1); } return options; }