List of usage examples for org.apache.commons.cli Options Options
Options
From source file:com.linkedin.bowser.tool.REPLCommandLine.java
public static void main(String... args) throws Exception { Logger root = Logger.getRootLogger(); Options options = new Options(); options.addOption("v", "verbose", false, "verbose output"); options.addOption("t", "threads", true, "parallel threads"); CommandLineParser parser = new PosixParser(); CommandLine cmdline = parser.parse(options, args); if (cmdline.hasOption("v")) root.setLevel(Level.DEBUG); else/* www.ja v a 2s . c o m*/ root.setLevel(Level.INFO); REPLCommandLine cmd = new REPLCommandLine(cmdline.hasOption("v"), cmdline.hasOption("t") ? Integer.parseInt(cmdline.getOptionValue("t")) : null); cmd.doRun(); }
From source file:com.ingby.socbox.bischeck.migration.Properties2ServerProperties.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new GnuParser(); CommandLine line = null;//from ww w .j a v a 2 s.com // create the Options Options options = new Options(); options.addOption("u", "usage", false, "show usage."); options.addOption("v", "verbose", false, "verbose - do not write to files"); options.addOption("s", "source", true, "directory old properties.xml is located"); options.addOption("d", "destination", true, "directory where the new xml files while be stored"); try { // parse the command line arguments line = parser.parse(options, args); } catch (org.apache.commons.cli.ParseException e) { System.out.println("Command parse error:" + e.getMessage()); Util.ShellExit(1); } if (line.hasOption("usage")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("DB2XMLConvert", options); Util.ShellExit(0); } Properties2ServerProperties converter = new Properties2ServerProperties(); if (line.hasOption("source")) { String sourcedir = line.getOptionValue("source"); String destdir = "."; if (line.hasOption("destination")) { destdir = line.getOptionValue("destination"); } converter.createXMLServerProperties(sourcedir, destdir); } }
From source file:io.s4.tools.loadgenerator.LoadGenerator.java
public static void main(String args[]) { Options options = new Options(); boolean warmUp = false; options.addOption(//from w w w . jav a 2 s . c o m OptionBuilder.withArgName("rate").hasArg().withDescription("Rate (events per second)").create("r")); options.addOption(OptionBuilder.withArgName("display_rate").hasArg() .withDescription("Display Rate at specified second boundary").create("d")); options.addOption(OptionBuilder.withArgName("adapter_address").hasArg() .withDescription("Address of client adapter").create("a")); options.addOption(OptionBuilder.withArgName("listener_application_name").hasArg() .withDescription("Listener application name").create("g")); options.addOption( OptionBuilder.withArgName("sleep_overhead").hasArg().withDescription("Sleep overhead").create("o")); options.addOption(new Option("w", "Warm-up")); CommandLineParser parser = new GnuParser(); CommandLine line = null; try { // parse the command line arguments line = parser.parse(options, args); } catch (ParseException exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); System.exit(1); } int expectedRate = 250; if (line.hasOption("r")) { try { expectedRate = Integer.parseInt(line.getOptionValue("r")); } catch (Exception e) { System.err.println("Bad expected rate specified " + line.getOptionValue("r")); System.exit(1); } } int displayRateIntervalSeconds = 20; if (line.hasOption("d")) { try { displayRateIntervalSeconds = Integer.parseInt(line.getOptionValue("d")); } catch (Exception e) { System.err.println("Bad display rate value specified " + line.getOptionValue("d")); System.exit(1); } } int updateFrequency = 0; if (line.hasOption("f")) { try { updateFrequency = Integer.parseInt(line.getOptionValue("f")); } catch (Exception e) { System.err.println("Bad query udpdate frequency specified " + line.getOptionValue("f")); System.exit(1); } System.out.printf("Update frequency is %d\n", updateFrequency); } String clientAdapterAddress = null; String clientAdapterHost = null; int clientAdapterPort = -1; if (line.hasOption("a")) { clientAdapterAddress = line.getOptionValue("a"); String[] parts = clientAdapterAddress.split(":"); if (parts.length != 2) { System.err.println("Bad adapter address specified " + clientAdapterAddress); System.exit(1); } clientAdapterHost = parts[0]; try { clientAdapterPort = Integer.parseInt(parts[1]); } catch (NumberFormatException nfe) { System.err.println("Bad adapter address specified " + clientAdapterAddress); System.exit(1); } } long sleepOverheadMicros = -1; if (line.hasOption("o")) { try { sleepOverheadMicros = Long.parseLong(line.getOptionValue("o")); } catch (NumberFormatException e) { System.err.println("Bad sleep overhead specified " + line.getOptionValue("o")); System.exit(1); } System.out.printf("Specified sleep overhead is %d\n", sleepOverheadMicros); } if (line.hasOption("w")) { warmUp = true; } List loArgs = line.getArgList(); if (loArgs.size() < 1) { System.err.println("No input file specified"); System.exit(1); } String inputFilename = (String) loArgs.get(0); LoadGenerator loadGenerator = new LoadGenerator(); loadGenerator.setInputFilename(inputFilename); loadGenerator.setDisplayRateInterval(displayRateIntervalSeconds); loadGenerator.setExpectedRate(expectedRate); loadGenerator.setClientAdapterHost(clientAdapterHost); loadGenerator.setClientAdapterPort(clientAdapterPort); loadGenerator.run(); System.exit(0); }
From source file:com.adobe.aem.demomachine.RegExp.java
public static void main(String[] args) throws IOException { String fileName = null;/*from ww w . j ava 2 s. c om*/ String regExp = null; String position = null; String value = "n/a"; List<String> allMatches = new ArrayList<String>(); // Command line options for this tool Options options = new Options(); options.addOption("f", true, "Filename"); options.addOption("r", true, "RegExp"); options.addOption("p", true, "Position"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { fileName = cmd.getOptionValue("f"); } if (cmd.hasOption("f")) { regExp = cmd.getOptionValue("r"); } if (cmd.hasOption("p")) { position = cmd.getOptionValue("p"); } if (fileName == null || regExp == null || position == null) { System.out.println("Command line parameters: -f fileName -r regExp -p position"); System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } String content = readFile(fileName, Charset.defaultCharset()); if (content != null) { Matcher m = Pattern.compile(regExp).matcher(content); while (m.find()) { String group = m.group(); int pos = group.indexOf(".zip"); if (pos > 0) { group = group.substring(0, pos); } logger.debug("RegExp: " + m.group() + " found returning " + group); allMatches.add(group); } if (allMatches.size() > 0) { if (position.equals("first")) { value = allMatches.get(0); } if (position.equals("last")) { value = allMatches.get(allMatches.size() - 1); } } } System.out.println(value); }
From source file:com.opensearchserver.textextractor.Main.java
public static void main(String[] args) throws IOException, ParseException { Logger.getLogger("").setLevel(Level.WARNING); Options options = new Options(); options.addOption("h", "help", false, "print this message"); options.addOption("p", "port", true, "TCP port"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar target/oss-text-extractor.jar", options); return;/*from w w w .j a v a 2 s. com*/ } int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 9091; UndertowJaxrsServer server = new UndertowJaxrsServer() .start(Undertow.builder().addHttpListener(port, "localhost")); server.deploy(Main.class); }
From source file:de.zazaz.iot.bosch.indego.util.IndegoMqttAdapter.java
public static void main(String[] args) { System.setProperty("log4j.configurationFile", "log4j2-indegoMqttAdapter-normal.xml"); Options options = new Options(); StringBuilder commandList = new StringBuilder(); for (DeviceCommand cmd : DeviceCommand.values()) { if (commandList.length() > 0) { commandList.append(", "); }/*from w w w .jav a2 s . co m*/ commandList.append(cmd.toString()); } options.addOption(Option // .builder("c") // .longOpt("config") // .desc("The configuration file to use") // .required() // .hasArg() // .build()); options.addOption(Option // .builder("d") // .longOpt("debug") // .desc("Logs more details") // .build()); options.addOption(Option // .builder("?") // .longOpt("help") // .desc("Prints this help") // .build()); CommandLineParser parser = new DefaultParser(); CommandLine cmds = null; try { cmds = parser.parse(options, args); } catch (ParseException ex) { System.err.println(ex.getMessage()); System.err.println(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(IndegoMqttAdapter.class.getName(), options); System.exit(1); return; } if (cmds.hasOption("?")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(CmdLineTool.class.getName(), options); return; } if (cmds.hasOption("d")) { System.setProperty("log4j.configurationFile", "log4j2-indegoMqttAdapter-debug.xml"); } String configFileName = cmds.getOptionValue('c'); File configFile = new File(configFileName); if (!configFile.exists()) { System.err.println(String.format("The specified config file (%s) does not exist", configFileName)); System.err.println(); System.exit(2); return; } Properties properties = new Properties(); try (InputStream in = new FileInputStream(configFile)) { properties.load(in); } catch (IOException ex) { System.err.println(ex.getMessage()); System.err.println(String.format("Was not able to load the properties file (%s)", configFileName)); System.err.println(); } MqttIndegoAdapterConfiguration config = new MqttIndegoAdapterConfiguration(); config.setIndegoBaseUrl(properties.getProperty("indego.mqtt.device.base-url")); config.setIndegoUsername(properties.getProperty("indego.mqtt.device.username")); config.setIndegoPassword(properties.getProperty("indego.mqtt.device.password")); config.setMqttBroker(properties.getProperty("indego.mqtt.broker.connection")); config.setMqttClientId(properties.getProperty("indego.mqtt.broker.client-id")); config.setMqttUsername(properties.getProperty("indego.mqtt.broker.username")); config.setMqttPassword(properties.getProperty("indego.mqtt.broker.password")); config.setMqttTopicRoot(properties.getProperty("indego.mqtt.broker.topic-root")); config.setPollingIntervalMs(Integer.parseInt(properties.getProperty("indego.mqtt.polling-interval-ms"))); MqttIndegoAdapter adapter = new MqttIndegoAdapter(config); adapter.startup(); }
From source file:io.lonelyrobot.empires.client.core.MainClientLauncher.java
public static void main(String[] args) { LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration(); cfg.title = Values.SUPERTITLE + " - " + Values.VERSION_NUMBER; final Options gameOptions = new Options(); // gameOptions.addOption("fullscreen", false, "Launch as fullscreen"); if (gameOptions.hasOption("fullscreen")) { System.out.println("Attempting to launch as fullscreen Application. This is experimental as of 1.3+"); GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); cfg.width = gd.getDisplayMode().getWidth(); cfg.height = gd.getDisplayMode().getHeight(); cfg.fullscreen = true;//from w w w . j a v a 2 s . co m Values.NEW_WIDTH = cfg.width; Values.NEW_HEIGHT = cfg.height; } else { cfg.fullscreen = false; cfg.width = Values.OLD_WIDTH; cfg.height = Values.OLD_HEIGHT; } cfg.useGL30 = true; cfg.resizable = false; cfg.initialBackgroundColor = Color.BLACK; new LwjglApplication(GameCore.getInstance(), cfg); }
From source file:com.rapleaf.hank.cli.AddDomain.java
public static void main(String[] args) throws InterruptedException, ParseException, IOException, InvalidConfigurationException { Options options = new Options(); options.addOption("n", "name", true, "the name of the domain to be created"); options.addOption("p", "num-parts", true, "the number of partitions for this domain"); options.addOption("f", "storage-engine-factory", true, "class name of the storage engine factory used by this domain"); options.addOption("o", "storage-engine-options", true, "path to a yaml file containing the options for the storage engine"); options.addOption("t", "partitioner", true, "class name of the partition used by this domain"); options.addOption("v", "initial-version", true, "initial version number of this domain"); options.addOption("c", "config", true, "path of a valid config file with coordinator connection information"); try {/* ww w . ja va2s .c o m*/ CommandLine line = new GnuParser().parse(options, args); CommandLineChecker.check(line, options, new String[] { "name", "num-parts", "storage-engine-factory", "storage-engine-options", "partitioner", "initial-version" }, AddDomain.class); Configurator configurator = new YamlClientConfigurator(line.getOptionValue("config")); addDomain(configurator, line.getOptionValue("name"), line.getOptionValue("num-parts"), line.getOptionValue("storage-engine-factory"), line.getOptionValue("storage-engine-options"), line.getOptionValue("partitioner"), line.getOptionValue("initial-version")); } catch (ParseException e) { new HelpFormatter().printHelp("add_domain", options); throw e; } }
From source file:net.geoprism.FileMerger.java
public static void main(String[] args) throws ParseException, IOException { CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption(Option.builder("b").hasArg().argName("baseFile").longOpt("baseFile") .desc("The path to the base properties file.").build()); options.addOption(Option.builder("o").hasArg().argName("overrideFile").longOpt("overrideFile") .desc("The path to the override properties file.").build()); options.addOption(Option.builder("e").hasArg().argName("exportFile").longOpt("exportFile") .desc("The path to the export properties file. A null value defaults to base.").build()); options.addOption(Option.builder("B").hasArg().argName("baseDir").longOpt("baseDir") .desc("The path to the base directory.").build()); options.addOption(Option.builder("O").hasArg().argName("overrideDir").longOpt("overrideDir") .desc("The path to the override directory.").build()); options.addOption(Option.builder("E").hasArg().argName("exportDir").longOpt("exportDir") .desc("The path to the export directory. A null value defaults to base.").build()); CommandLine line = parser.parse(options, args); String sBase = line.getOptionValue("b"); String sOverride = line.getOptionValue("o"); String sExport = line.getOptionValue("e"); String sBaseDir = line.getOptionValue("B"); String sOverrideDir = line.getOptionValue("O"); String sExportDir = line.getOptionValue("E"); if (sBase != null && sOverride != null) { if (sExport == null) { sExport = sBase;/*from w w w .ja v a 2s.c o m*/ } File fBase = new File(sBase); File fOverride = new File(sOverride); File fExport = new File(sExport); if (!fBase.exists() || !fOverride.exists()) { throw new RuntimeException( "The base [" + sBase + "] and the override [" + sOverride + "] paths must both exist."); } FileMerger merger = new FileMerger(); merger.mergeProperties(fBase, fOverride, fExport); } else if (sBaseDir != null && sOverrideDir != null) { if (sExportDir == null) { sExportDir = sBaseDir; } File fBaseDir = new File(sBaseDir); File fOverrideDir = new File(sOverrideDir); File fExportDir = new File(sExportDir); if (!fBaseDir.exists() || !fOverrideDir.exists()) { throw new RuntimeException("The base [" + sBaseDir + "] and the override [" + sOverrideDir + "] paths must both exist."); } FileMerger merger = new FileMerger(); merger.mergeDirectories(fBaseDir, fOverrideDir, fExportDir); } else { throw new RuntimeException("Invalid arguments"); } }
From source file:edu.cmu.lti.oaqa.knn4qa.apps.QueryGenNMSLIB.java
public static void main(String[] args) { Options options = new Options(); options.addOption(CommonParams.QUERY_FILE_PARAM, null, true, CommonParams.QUERY_FILE_DESC); options.addOption(CommonParams.MEMINDEX_PARAM, null, true, CommonParams.MEMINDEX_DESC); options.addOption(CommonParams.KNN_QUERIES_PARAM, null, true, CommonParams.KNN_QUERIES_DESC); options.addOption(CommonParams.NMSLIB_FIELDS_PARAM, null, true, CommonParams.NMSLIB_FIELDS_DESC); options.addOption(CommonParams.MAX_NUM_QUERY_PARAM, null, true, CommonParams.MAX_NUM_QUERY_DESC); options.addOption(CommonParams.SEL_PROB_PARAM, null, true, CommonParams.SEL_PROB_DESC); CommandLineParser parser = new org.apache.commons.cli.GnuParser(); BufferedWriter knnQueries = null; int maxNumQuery = Integer.MAX_VALUE; Float selProb = null;/*from w w w. j a va2 s . c o m*/ try { CommandLine cmd = parser.parse(options, args); String queryFile = null; if (cmd.hasOption(CommonParams.QUERY_FILE_PARAM)) { queryFile = cmd.getOptionValue(CommonParams.QUERY_FILE_PARAM); } else { Usage("Specify 'query file'", options); } String knnQueriesFile = cmd.getOptionValue(CommonParams.KNN_QUERIES_PARAM); if (null == knnQueriesFile) Usage("Specify '" + CommonParams.KNN_QUERIES_DESC + "'", options); String tmpn = cmd.getOptionValue(CommonParams.MAX_NUM_QUERY_PARAM); if (tmpn != null) { try { maxNumQuery = Integer.parseInt(tmpn); } catch (NumberFormatException e) { Usage("Maximum number of queries isn't integer: '" + tmpn + "'", options); } } String tmps = cmd.getOptionValue(CommonParams.NMSLIB_FIELDS_PARAM); if (null == tmps) Usage("Specify '" + CommonParams.NMSLIB_FIELDS_DESC + "'", options); String nmslibFieldList[] = tmps.split(","); knnQueries = new BufferedWriter(new FileWriter(knnQueriesFile)); knnQueries.write("isQueryFile=1"); knnQueries.newLine(); knnQueries.newLine(); String memIndexPref = cmd.getOptionValue(CommonParams.MEMINDEX_PARAM); if (null == memIndexPref) { Usage("Specify '" + CommonParams.MEMINDEX_DESC + "'", options); } String tmpf = cmd.getOptionValue(CommonParams.SEL_PROB_PARAM); if (tmpf != null) { try { selProb = Float.parseFloat(tmpf); } catch (NumberFormatException e) { Usage("A selection probability isn't a number in the range (0,1)'" + tmpf + "'", options); } if (selProb < Float.MIN_NORMAL || selProb + Float.MIN_NORMAL >= 1) Usage("A selection probability isn't a number in the range (0,1)'" + tmpf + "'", options); } BufferedReader inpText = new BufferedReader( new InputStreamReader(CompressUtils.createInputStream(queryFile))); String docText = XmlHelper.readNextXMLIndexEntry(inpText); NmslibQueryGenerator queryGen = new NmslibQueryGenerator(nmslibFieldList, memIndexPref); Random rnd = new Random(); for (int docNum = 1; docNum <= maxNumQuery && docText != null; ++docNum, docText = XmlHelper.readNextXMLIndexEntry(inpText)) { if (selProb != null) { if (rnd.nextFloat() > selProb) continue; } Map<String, String> docFields = null; try { docFields = XmlHelper.parseXMLIndexEntry(docText); String queryObjStr = queryGen.getStrObjForKNNService(docFields); knnQueries.append(queryObjStr); knnQueries.newLine(); } catch (SAXException e) { System.err.println("Parsing error, offending DOC:" + NL + docText + " doc # " + docNum); throw new Exception("Parsing error."); } } knnQueries.close(); } catch (ParseException e) { Usage("Cannot parse arguments", options); if (null != knnQueries) try { knnQueries.close(); } catch (IOException e1) { e1.printStackTrace(); } } catch (Exception e) { System.err.println("Terminating due to an exception: " + e); try { if (knnQueries != null) knnQueries.close(); } catch (IOException e1) { e1.printStackTrace(); } System.exit(1); } System.out.println("Terminated successfully!"); }