List of usage examples for org.apache.commons.cli CommandLine getOptionValues
public String[] getOptionValues(char opt)
From source file:com.github.jjYBdx4IL.utils.lang.ConstantClassCreator.java
public void run(CommandLine line) throws IOException, JClassAlreadyExistsException, ParseException { String classname = line.getOptionValue(OPTNAME_OUTPUT_CLASSNAME); if (classname == null || classname.isEmpty()) { throw new ParseException("--" + OPTNAME_OUTPUT_CLASSNAME + " required"); }// w w w .ja v a2 s. com String[] sysPropNames = line.getOptionValues(OPTNAME_SYSPROP); if (sysPropNames.length == 0) { throw new ParseException("--" + OPTNAME_SYSPROP + " required"); } String outputDirName = line.getOptionValue(OPTNAME_OUTPUT_DIRECTORY); if (outputDirName == null || outputDirName.isEmpty()) { throw new ParseException("--" + OPTNAME_OUTPUT_DIRECTORY + " required"); } File outputDir = new File(outputDirName); if (!outputDir.exists()) { outputDir.mkdirs(); } JCodeModel cm = new JCodeModel(); JDefinedClass cls = cm._class(classname); for (String sysPropName : sysPropNames) { String value = System.getProperty(sysPropName); cls.field(JMod.PUBLIC | JMod.FINAL | JMod.STATIC, String.class, WordUtils.camelCase(sysPropName), value == null ? JExpr._null() : JExpr.lit(value)); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); cm.build(new ProgressCodeWriter(new FileCodeWriter(outputDir), new PrintStream(baos) { @Override public void print(final String msg) { LOG.info("creating: " + msg); } })); }
From source file:net.sourceforge.czt.gnast.Gnast.java
/** * Parses the arguments from the command line. * * @return a configured GnAST builder if parsing was successful; * {@code null} otherwise./* w w w . jav a 2 s . c o m*/ * @throws NullPointerException if {@code args} is {@code null} */ @SuppressWarnings("static-access") private static GnastBuilder parseArguments(String[] args) { Options argOptions = new Options(); OptionGroup verboseOptions = new OptionGroup(); verboseOptions.addOption(OptionBuilder.withLongOpt("verbose") .withDescription("Verbose; display verbose debugging messages").create("v")); verboseOptions.addOption(OptionBuilder.withLongOpt("vverbose") .withDescription("Very verbose; more verbose debugging messages").create("vv")); verboseOptions.addOption(OptionBuilder.withLongOpt("vvverbose") .withDescription("Very very verbose; even more verbose debugging messages").create("vvv")); argOptions.addOptionGroup(verboseOptions); argOptions.addOption(OptionBuilder.withLongOpt("finalizers") .withDescription("Add AST finalisers. WARNING: ASTs will consume more memory!").create("f")); argOptions.addOption(OptionBuilder.withArgName("dir").hasArg().withLongOpt("destination") .withDescription("Generated files go into this directory").create("d")); argOptions.addOption(OptionBuilder.withArgName("dir1 dir2").hasArgs().withValueSeparator(',') .withLongOpt("templates").withDescription("Additional template directories").create("t")); argOptions.addOption(OptionBuilder.withArgName("file").hasArg().withLongOpt("mapping") .withDescription("XML type mapping properties file").create("m")); argOptions.addOption(OptionBuilder.withArgName("dir").hasArg().withLongOpt("source").withDescription( "The directory with all ZML schema files. The requested project namespace must be present, as well as all its parents.") .create("s")); argOptions.addOption(OptionBuilder.withArgName("url").hasArg().withLongOpt("namespace") .withDescription("The namespace of the project to be generated.").create("n")); // use GNU parser that allows longer option name (e.g. `-vvv`) CommandLineParser parser = new GnuParser(); CommandLine line; try { // parse the command line arguments line = parser.parse(argOptions, args); } catch (ParseException exp) { // oops, something went wrong System.err.println(exp.getMessage()); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("gnast", argOptions, true); return null; } Level verbosity = line.hasOption("v") ? Level.INFO : (line.hasOption("vv") ? Level.FINE : (line.hasOption("vvv") ? Level.FINER : Level.OFF)); String[] templates = line.getOptionValues("t"); List<URL> templateDirs = new ArrayList<URL>(); for (String path : templates) { templateDirs.add(toURL(path)); } return new GnastBuilder().verbosity(verbosity).finalizers(line.hasOption("f")) .destination(toFile(line.getOptionValue("d"))).templates(templateDirs) .mapping(toURL(line.getOptionValue("m"))).sourceSchemas(schemaDirToURL(line.getOptionValue("s"))) .namespace(line.getOptionValue("n")); }
From source file:com.ebay.jetstream.application.JetstreamApplication.java
/** * Parse the options given on the command line. This method may be overridden for application specific command line * option handling.//from w w w . j a v a2s. c o m * * @param commandLine * the parsed command line. */ protected void parseOptions(CommandLine commandLine) { JetstreamApplicationInformation ai = getApplicationInformation(); if (commandLine.hasOption('b')) { ai.setBeans(commandLine.getOptionValues('b')); } if (commandLine.hasOption('c')) { ai.setConfigRoots(commandLine.getOptionValues('c')); } if (commandLine.hasOption("cv")) { ai.setConfigVersion(commandLine.getOptionValue("cv")); } if (commandLine.hasOption('n')) { ai.setApplicationName(commandLine.getOptionValue('n')); } if (commandLine.hasOption('p')) { ai.setManagementPort(Integer.valueOf(commandLine.getOptionValue('p'))); System.setProperty("jetty_port", commandLine.getOptionValue('p')); } else { System.setProperty("jetty_port", String.valueOf(9999)); } if (commandLine.hasOption('z')) { ai.setZone(commandLine.getOptionValue('z')); } if (commandLine.hasOption("nd")) { ai.useDNS(false); } if (commandLine.hasOption("wqz")) { ai.setWorkQueueSz(Integer.valueOf(commandLine.getOptionValue("wqz"))); } if (commandLine.hasOption("wt")) { ai.setWorkerThreads(Integer.valueOf(commandLine.getOptionValue("wt"))); } }
From source file:com.spotify.hdfs2cass.BulkLoader.java
public int run(String[] args) throws Exception { CommandLine cmdLine = parseOptions(args); String[] inputPaths = cmdLine.getOptionValues('i'); String seedNodeHost = cmdLine.getOptionValue('h'); String seedNodePort = cmdLine.getOptionValue('p', "9160"); String keyspace = cmdLine.getOptionValue('k'); String colfamily = cmdLine.getOptionValue('c'); int mappers = Integer.parseInt(cmdLine.getOptionValue('m', "0")); Integer copiers = Integer.parseInt(cmdLine.getOptionValue('P', "0")); String poolName = cmdLine.getOptionValue("pool"); ClusterInfo clusterInfo = new ClusterInfo(seedNodeHost, seedNodePort); clusterInfo.init(keyspace);//from w ww. j a v a2 s. c o m final String partitionerClass = clusterInfo.getPartitionerClass(); final int reducers = adjustReducers(Integer.parseInt(cmdLine.getOptionValue('r', "0")), clusterInfo.getNumClusterNodes()); Configuration conf = new Configuration(); ConfigHelper.setOutputColumnFamily(conf, keyspace, colfamily); ConfigHelper.setOutputInitialAddress(conf, seedNodeHost); ConfigHelper.setOutputRpcPort(conf, seedNodePort); ConfigHelper.setOutputPartitioner(conf, partitionerClass); if (cmdLine.hasOption('s')) { conf.set("mapreduce.output.bulkoutputformat.buffersize", cmdLine.getOptionValue('s', "32")); } if (cmdLine.hasOption('M')) { conf.set("mapreduce.output.bulkoutputformat.streamthrottlembits", cmdLine.getOptionValue('M')); } if (cmdLine.hasOption('C')) { ConfigHelper.setOutputCompressionClass(conf, cmdLine.getOptionValue('C')); } if (cmdLine.hasOption('b')) { conf.setBoolean("com.spotify.hdfs2cass.base64", true); } JobConf job = new JobConf(conf); if (mappers > 0) job.setNumMapTasks(mappers); if (reducers > 0) job.setNumReduceTasks(reducers); if (copiers > 0) job.set("mapred.reduce.parallel.copies", copiers.toString()); if (poolName != null) job.set("mapred.fairscheduler.pool", poolName); // set the nodes as a param for the other hadoop nodes clusterInfo.setConf(job); String jobName = "bulkloader-hdfs-to-cassandra"; if (cmdLine.hasOption('n')) jobName += "-" + cmdLine.getOptionValue('n'); job.setJobName(jobName); job.setJarByClass(BulkLoader.class); job.setInputFormat(AvroAsTextInputFormat.class); for (String inputPath : inputPaths) { FileInputFormat.addInputPath(job, new Path(inputPath)); } //map just outputs text, reduce sends to cassandra job.setMapperClass(MapToText.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(Text.class); job.setPartitionerClass(CassandraPartitioner.class); job.setReducerClass(ReduceTextToCassandra.class); job.setOutputKeyClass(ByteBuffer.class); job.setOutputValueClass(List.class); if (cmdLine.hasOption('s')) job.setOutputFormat(BulkOutputFormat.class); else job.setOutputFormat(ColumnFamilyOutputFormat.class); JobClient.runJob(job); return 0; }
From source file:kina.testutils.ContextProperties.java
/** * Public constructor./*from w w w .ja v a 2s .c o m*/ */ public ContextProperties(String[] args) { Options options = new Options(); options.addOption("m", "master", true, "The spark's master endpoint"); options.addOption("h", "sparkHome", true, "The spark's home, eg. /opt/spark"); options.addOption("H", "cassandraHost", true, "Cassandra endpoint"); options.addOption(OptionBuilder.hasArg().withType(Integer.class).withLongOpt("cassandraCqlPort") .withArgName("cassandra_cql_port").withDescription("cassandra's cql port, defaults to 9042") .create()); options.addOption(OptionBuilder.hasArg().withType(Integer.class).withLongOpt("cassandraThriftPort") .withArgName("cassandra_thrift_port") .withDescription("cassandra's thrift port, " + "defaults to 9160").create()); options.addOption(OptionBuilder.hasArg().withValueSeparator(',').withLongOpt("jars") .withArgName("jars_to_add").withDescription("comma separated list of jars to add").create()); Option help = new Option("help", "print this message"); //options.addOption("j","jars", true, "comma separated list of jars to add"); options.addOption(help); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); try { CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { formatter.printHelp("", options); throw new GenericException("Help command issued"); } jar = (line.hasOption("jars") ? line.getOptionValues("jars") : new String[] {}); cluster = line.getOptionValue("master", defaultIfEmpty(System.getProperty("spark.master"), "local")); sparkHome = line.getOptionValue("sparkHome", defaultIfEmpty(System.getProperty("spark.home"), "")); cassandraHost = line.getOptionValue("cassandraHost", Constants.DEFAULT_CASSANDRA_HOST); cassandraCqlPort = line.hasOption("cassandraCqlPort") ? Integer.parseInt(line.getOptionValue("cassandraCqlPort")) : Constants.DEFAULT_CASSANDRA_CQL_PORT; cassandraThriftPort = line.hasOption("cassandraThriftPort") ? Integer.parseInt(line.getOptionValue("cassandraThriftPort")) : Constants.DEFAULT_CASSANDRA_RPC_PORT; } catch (ParseException e) { formatter.printHelp("", options); LOG.error("Unexpected exception: ", e); } }
From source file:com.stratio.deep.examples.utils.ContextProperties.java
/** * Public constructor.//from w w w. j a v a2s .c o m */ public ContextProperties(String[] args) { Options options = new Options(); options.addOption("m", "master", true, "The spark's master endpoint"); options.addOption("h", "sparkHome", true, "The spark's home, eg. /opt/spark"); options.addOption("H", "cassandraHost", true, "Cassandra endpoint"); options.addOption(OptionBuilder.hasArg().withType(Integer.class).withLongOpt("cassandraCqlPort") .withArgName("cassandra_cql_port").withDescription("cassandra's cql port, defaults to 9042") .create()); options.addOption(OptionBuilder.hasArg().withType(Integer.class).withLongOpt("cassandraThriftPort") .withArgName("cassandra_thrift_port") .withDescription("cassandra's thrift port, " + "defaults to 9160").create()); options.addOption(OptionBuilder.hasArg().withValueSeparator(',').withLongOpt("jars") .withArgName("jars_to_add").withDescription("comma separated list of jars to add").create()); Option help = new Option("help", "print this message"); //options.addOption("j","jars", true, "comma separated list of jars to add"); options.addOption(help); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); try { CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { formatter.printHelp("", options); throw new DeepGenericException("Help command issued"); } jar = (line.hasOption("jars") ? line.getOptionValues("jars") : new String[] {}); cluster = line.getOptionValue("master", defaultIfEmpty(System.getProperty("spark.master"), "local")); sparkHome = line.getOptionValue("sparkHome", defaultIfEmpty(System.getProperty("spark.home"), "")); cassandraHost = line.getOptionValue("cassandraHost", Constants.DEFAULT_CASSANDRA_HOST); cassandraCqlPort = line.hasOption("cassandraCqlPort") ? Integer.parseInt(line.getOptionValue("cassandraCqlPort")) : Constants.DEFAULT_CASSANDRA_CQL_PORT; cassandraThriftPort = line.hasOption("cassandraThriftPort") ? Integer.parseInt(line.getOptionValue("cassandraThriftPort")) : Constants.DEFAULT_CASSANDRA_RPC_PORT; } catch (ParseException e) { formatter.printHelp("", options); LOG.error("Unexpected exception: ", e); } }
From source file:com.github.mrstampy.poisonivy.PoisonIvy.java
private void addXOptions(CommandLine cli, List<String> command) { String[] xs = cli.getOptionValues("X"); if (xs == null || xs.length == 0) return;/*from w w w. j a v a 2s .c o m*/ for (String x : xs) { command.add("-X" + x); } }
From source file:co.turnus.analysis.partitioning.CommunicationCostPartitioningCli.java
private static Configuration parseCommandLine(CommandLine cmd) throws ParseException { Configuration config = new BaseConfiguration(); StringBuffer s = new StringBuffer(); config.setProperty(VERBOSE, cmd.hasOption("v")); if (!cmd.hasOption("t")) { s.append("Trace project directory not specified. "); } else {/* w w w. jav a 2 s .c om*/ String fileName = cmd.getOptionValue("t", ""); File file = new File(fileName); if (file == null || !file.exists()) { s.append("Trace project does not exists. "); } else { config.setProperty(TRACE_PROJECT, fileName); } } if (!cmd.hasOption("o")) { s.append("Output directory not specified. "); } else { String fileName = cmd.getOptionValue("o", ""); File file = new File(fileName); if (file == null || !file.exists()) { s.append("Output directory does not exists. "); } else { config.setProperty(OUTPUT_PATH, fileName); } } if (!cmd.hasOption("p")) { s.append("The number of partitions is not specified. "); } else { String[] sp = cmd.getOptionValues("p"); if (sp.length == 1) { int value = Integer.parseInt(sp[0]); config.addProperty(PARTITION_UNITS_MIN, value); config.addProperty(PARTITION_UNITS_MAX, value); config.addProperty(PARTITION_UNITS_POINTS, 1); } else if (sp.length == 2) { int min = Integer.parseInt(sp[0]); int max = Integer.parseInt(sp[1]); config.addProperty(PARTITION_UNITS_MIN, min); config.addProperty(PARTITION_UNITS_MAX, max); config.addProperty(PARTITION_UNITS_POINTS, max - min + 1); } else { int min = Integer.parseInt(sp[0]); int max = Integer.parseInt(sp[1]); int points = Integer.parseInt(sp[2]); config.addProperty(PARTITION_UNITS_MIN, min); config.addProperty(PARTITION_UNITS_MAX, max); config.addProperty(PARTITION_UNITS_POINTS, points); } } if (cmd.hasOption("xls")) { String fileName = cmd.getOptionValue("xls", ""); if (fileName == null || fileName.isEmpty()) { s.append("XLS file name is not correct. "); } else { config.setProperty(XLS, fileName); } } if (cmd.hasOption("xcf")) { String fileName = cmd.getOptionValue("xcf", ""); if (fileName == null || fileName.isEmpty()) { s.append("XCF file name is not correct. "); } else { config.setProperty(XCF, fileName); } } String error = s.toString(); if (!error.isEmpty()) { throw new ParseException(error); } return config; }
From source file:com.opengamma.financial.generator.AbstractPortfolioGeneratorTool.java
private Currency[] parseCurrencies(final CommandLine commandLine) { if (commandLine.hasOption(CURRENCIES_OPT)) { final String[] currencies = commandLine.getOptionValues(CURRENCIES_OPT); final Currency[] ccys = new Currency[currencies.length]; int i = 0; for (final String ccyStr : currencies) { ccys[i++] = Currency.of(ccyStr.trim()); }/*w ww . jav a2 s . c o m*/ return ccys; } else { return null; } }
From source file:io.github.discovermovies.datacollector.movie.Application.java
private void executeCommand(CommandLine cmd) { if (cmd.hasOption("v")) { System.out.println(APPLICATION_NAME + " Version " + VERSION); System.out.println(COPYRIGHT); }/*from www. j av a 2 s .c o m*/ if (cmd.hasOption("h")) { printHelp(); } if (cmd.hasOption("u")) { String[] argList = cmd.getOptionValues("u"); startCollectingData(argList[0], argList[1]); } if (cmd.hasOption("d")) { if (cmd.hasOption("u")) { String[] argList = cmd.getOptionValues("u"); startCollectingData(argList[0], argList[1], cmd.getOptionValue("d")); } else { System.err.println("Unspecified Credentials.\n use paramenter -u"); printHelp(); } } }