List of usage examples for org.apache.commons.cli CommandLine getOptions
public Option[] getOptions()
From source file:com.cyberway.issue.crawler.extractor.ExtractorTool.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option("h", "help", false, "Prints this message and exits.")); StringBuffer defaultExtractors = new StringBuffer(); for (int i = 0; i < DEFAULT_EXTRACTORS.length; i++) { if (i > 0) { defaultExtractors.append(", "); }//from ww w . j a v a2s . c o m defaultExtractors.append(DEFAULT_EXTRACTORS[i]); } options.addOption(new Option("e", "extractor", true, "List of comma-separated extractor class names. " + "Run in order listed. " + "If no extractors listed, runs following: " + defaultExtractors.toString() + ".")); options.addOption( new Option("s", "scratch", true, "Directory to write scratch files to. Default: '/tmp'.")); PosixParser parser = new PosixParser(); CommandLine cmdline = parser.parse(options, args, false); List cmdlineArgs = cmdline.getArgList(); Option[] cmdlineOptions = cmdline.getOptions(); HelpFormatter formatter = new HelpFormatter(); // If no args, print help. if (cmdlineArgs.size() <= 0) { usage(formatter, options, 0); } // Now look at options passed. String[] extractors = DEFAULT_EXTRACTORS; String scratch = null; for (int i = 0; i < cmdlineOptions.length; i++) { switch (cmdlineOptions[i].getId()) { case 'h': usage(formatter, options, 0); break; case 'e': String value = cmdlineOptions[i].getValue(); if (value == null || value.length() <= 0) { // Allow saying NO extractors so we can see // how much it costs just reading through // ARCs. extractors = new String[0]; } else { extractors = value.split(","); } break; case 's': scratch = cmdlineOptions[i].getValue(); break; default: throw new RuntimeException("Unexpected option: " + +cmdlineOptions[i].getId()); } } ExtractorTool tool = new ExtractorTool(extractors, scratch); for (Iterator i = cmdlineArgs.iterator(); i.hasNext();) { tool.extract((String) i.next()); } }
From source file:com.esri.geoevent.test.performance.OrchestratorMain.java
/** * Main method - this is used to when running from command line * * @param args Command Line Arguments//from ww w. j a va2 s . c o m */ @SuppressWarnings("static-access") public static void main(String[] args) { // TODO: Localize the messages // test harness options Options testHarnessOptions = new Options(); testHarnessOptions.addOption(OptionBuilder.withLongOpt("fixtures") .withDescription("The fixtures xml file to load and configure the performance test harness.") .hasArg().create("f")); testHarnessOptions.addOption("h", "help", false, "print the help message"); // parse the command line CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(testHarnessOptions, args, false); } catch (ParseException ignore) { printHelp(testHarnessOptions); return; } if (cmd.getOptions().length == 0) { OrchestratorUI ui = new OrchestratorUI(); ui.run(args); } else { if (cmd.hasOption("h")) { printHelp(testHarnessOptions); return; } if (cmd.hasOption("h") || !cmd.hasOption("f")) { printHelp(testHarnessOptions); return; } String fixturesFilePath = cmd.getOptionValue("f"); // validate if (!validateFixturesFile(fixturesFilePath)) { printHelp(testHarnessOptions); return; } // parse the xml file final Fixtures fixtures; try { fixtures = fromXML(fixturesFilePath); } catch (JAXBException error) { System.err.println(ImplMessages.getMessage("TEST_HARNESS_EXECUTOR_CONFIG_ERROR", fixturesFilePath)); error.printStackTrace(); return; } // run the test harness try { OrchestratorRunner executor = new OrchestratorRunner(fixtures); executor.start(); } catch (RunningException error) { error.printStackTrace(); } } }
From source file:net.kahowell.xsd.fuzzer.XmlGenerator.java
/** * Drives the application, parsing command-line arguments to determine * options./*from w w w .j ava 2 s. c om*/ * * @param args command line args */ public static void main(String[] args) { try { setupLog4j(); CommandLine commandLine = parser.parse(ConsoleOptions.OPTIONS, args); if (commandLine.hasOption("d")) { Logger.getLogger("net.kahowell.xsd.fuzzer").setLevel(Level.DEBUG); } for (Option option : commandLine.getOptions()) { if (option.getValue() != null) { log.debug("Using " + option.getDescription() + ": " + option.getValue()); } else { log.debug("Using " + option.getDescription()); } } Injector injector = Guice.createInjector( Modules.override(Modules.combine(new DefaultGeneratorsModule(), new DefaultOptionsModule())) .with(new CommandLineArgumentsModule(commandLine))); log.debug(injector.getBindings()); XsdParser xsdParser = injector.getInstance(XsdParser.class); XmlOptions xmlOptions = injector .getInstance(Key.get(XmlOptions.class, Names.named("xml save options"))); XmlGenerator xmlGenerator = injector.getInstance(XmlGenerator.class); XmlGenerationOptions xmlGenerationOptions = injector.getInstance(XmlGenerationOptions.class); doPostModuleConfig(commandLine, xmlGenerationOptions, injector); ByteArrayOutputStream stream = new ByteArrayOutputStream(); XmlObject generatedXml = xsdParser.generateXml(commandLine.getOptionValue("root")); generatedXml.save(stream, xmlOptions); if (commandLine.hasOption("v")) { if (xsdParser.validate(stream)) { log.info("Valid XML file produced."); } else { log.info("Invalid XML file produced."); System.exit(4); } } xmlGenerator.showOrSave(stream); } catch (MissingOptionException e) { if (e.getMissingOptions().size() != 0) { System.err.println("Missing argument(s): " + Arrays.toString(e.getMissingOptions().toArray())); } helpFormatter.printHelp(XmlGenerator.class.getSimpleName(), ConsoleOptions.OPTIONS); System.exit(1); } catch (ParseException e) { helpFormatter.printHelp(XmlGenerator.class.getSimpleName(), ConsoleOptions.OPTIONS); System.exit(2); } catch (Exception e) { e.printStackTrace(); System.exit(3); } }
From source file:com.redhat.poc.jdg.bankofchina.util.GenerateUserIdCsv.java
public static void main(String[] args) throws Exception { CommandLine commandLine; Options options = new Options(); options.addOption("s", true, "The start csv file number option"); options.addOption("e", true, "The end csv file number option"); BasicParser parser = new BasicParser(); parser.parse(options, args);/*from w w w.j a v a 2 s . c o m*/ commandLine = parser.parse(options, args); if (commandLine.getOptions().length > 0) { if (commandLine.hasOption("s")) { String start = commandLine.getOptionValue("s"); if (start != null && start.length() > 0) { csvFileStart = Integer.parseInt(start); } } if (commandLine.hasOption("e")) { String end = commandLine.getOptionValue("e"); if (end != null && end.length() > 0) { csvFileEnd = Integer.parseInt(end); } } } for (int i = csvFileStart; i <= csvFileEnd; i++) { ReadCsvFile(i); } System.out.println(); System.out.println("%%%%%%%%% " + csvFileStart + "-" + csvFileEnd + " ? userid.csv ,? %%%%%%%%%"); System.out.println("%%%%%%%%% userid.csv " + userIdList.size() + " ? %%%%%%%%%"); CSVWriter writer = new CSVWriter(new FileWriter(CSV_FILE_PATH + "userid.csv")); writer.writeAll(userIdList); writer.flush(); writer.close(); }
From source file:com.cyberway.issue.io.warc.WARCReader.java
/** * Command-line interface to WARCReader. * * Here is the command-line interface:/* ww w . j a va 2 s. com*/ * <pre> * usage: java com.cyberway.issue.io.arc.WARCReader [--offset=#] ARCFILE * -h,--help Prints this message and exits. * -o,--offset Outputs record at this offset into arc file.</pre> * * <p>Outputs using a pseudo-CDX format as described here: * <a href="http://www.archive.org/web/researcher/cdx_legend.php">CDX * Legent</a> and here * <a href="http://www.archive.org/web/researcher/example_cdx.php">Example</a>. * Legend used in below is: 'CDX b e a m s c V (or v if uncompressed) n g'. * Hash is hard-coded straight SHA-1 hash of content. * * @param args Command-line arguments. * @throws ParseException Failed parse of the command line. * @throws IOException * @throws java.text.ParseException */ public static void main(String[] args) throws ParseException, IOException, java.text.ParseException { Options options = getOptions(); PosixParser parser = new PosixParser(); CommandLine cmdline = parser.parse(options, args, false); List cmdlineArgs = cmdline.getArgList(); Option[] cmdlineOptions = cmdline.getOptions(); HelpFormatter formatter = new HelpFormatter(); // If no args, print help. if (cmdlineArgs.size() <= 0) { usage(formatter, options, 0); } // Now look at options passed. long offset = -1; boolean digest = false; boolean strict = false; String format = CDX; for (int i = 0; i < cmdlineOptions.length; i++) { switch (cmdlineOptions[i].getId()) { case 'h': usage(formatter, options, 0); break; case 'o': offset = Long.parseLong(cmdlineOptions[i].getValue()); break; case 's': strict = true; break; case 'd': digest = getTrueOrFalse(cmdlineOptions[i].getValue()); break; case 'f': format = cmdlineOptions[i].getValue().toLowerCase(); boolean match = false; // List of supported formats. final String[] supportedFormats = { CDX, DUMP, GZIP_DUMP, CDX_FILE }; for (int ii = 0; ii < supportedFormats.length; ii++) { if (supportedFormats[ii].equals(format)) { match = true; break; } } if (!match) { usage(formatter, options, 1); } break; default: throw new RuntimeException("Unexpected option: " + +cmdlineOptions[i].getId()); } } if (offset >= 0) { if (cmdlineArgs.size() != 1) { System.out.println("Error: Pass one arcfile only."); usage(formatter, options, 1); } WARCReader r = WARCReaderFactory.get(new File((String) cmdlineArgs.get(0)), offset); r.setStrict(strict); outputRecord(r, format); } else { for (Iterator i = cmdlineArgs.iterator(); i.hasNext();) { String urlOrPath = (String) i.next(); try { WARCReader r = WARCReaderFactory.get(urlOrPath); r.setStrict(strict); r.setDigest(digest); output(r, format); } catch (RuntimeException e) { // Write out name of file we failed on to help with // debugging. Then print stack trace and try to keep // going. We do this for case where we're being fed // a bunch of ARCs; just note the bad one and move // on to the next. System.err.println("Exception processing " + urlOrPath + ": " + e.getMessage()); e.printStackTrace(System.err); System.exit(1); } } } }
From source file:com.redhat.poc.jdg.bankofchina.function.TestCase413RemoteMultiThreads.java
public static void main(String[] args) throws Exception { CommandLine commandLine; Options options = new Options(); options.addOption("s", true, "The start csv file number option"); options.addOption("e", true, "The end csv file number option"); BasicParser parser = new BasicParser(); parser.parse(options, args);/* w w w . ja va2 s . c o m*/ commandLine = parser.parse(options, args); if (commandLine.getOptions().length > 0) { if (commandLine.hasOption("s")) { String start = commandLine.getOptionValue("s"); if (start != null && start.length() > 0) { csvFileStart = Integer.parseInt(start); } } if (commandLine.hasOption("e")) { String end = commandLine.getOptionValue("e"); if (end != null && end.length() > 0) { csvFileEnd = Integer.parseInt(end); } } } System.out.println( "%%%%%%%%% csv ?, ?, ?(ms)," + new Date().getTime()); for (int i = csvFileStart; i <= csvFileEnd; i++) { new TestCase413RemoteMultiThreads(i).start(); } }
From source file:com.redhat.poc.jdg.bankofchina.function.TestCase411RemoteMultiThreads.java
public static void main(String[] args) throws Exception { CommandLine commandLine; Options options = new Options(); options.addOption("s", true, "The start csv file number option"); options.addOption("e", true, "The end csv file number option"); BasicParser parser = new BasicParser(); parser.parse(options, args);/*from w w w .j a va 2 s. co m*/ commandLine = parser.parse(options, args); if (commandLine.getOptions().length > 0) { if (commandLine.hasOption("s")) { String start = commandLine.getOptionValue("s"); if (start != null && start.length() > 0) { csvFileStart = Integer.parseInt(start); } } if (commandLine.hasOption("e")) { String end = commandLine.getOptionValue("e"); if (end != null && end.length() > 0) { csvFileEnd = Integer.parseInt(end); } } } System.out.println( "%%%%%%%%% csv ?, ?, ?(ms)," + new Date().getTime()); for (int i = csvFileStart; i <= csvFileEnd; i++) { new TestCase411RemoteMultiThreads(i).start(); } }
From source file:com.redhat.poc.jdg.bankofchina.function.TestCase412RemoteMultiThreads.java
public static void main(String[] args) throws Exception { CommandLine commandLine; Options options = new Options(); options.addOption("s", true, "The start csv file number option"); options.addOption("e", true, "The end csv file number option"); BasicParser parser = new BasicParser(); parser.parse(options, args);//from w ww. j av a 2 s. co m commandLine = parser.parse(options, args); if (commandLine.getOptions().length > 0) { if (commandLine.hasOption("s")) { String start = commandLine.getOptionValue("s"); if (start != null && start.length() > 0) { csvFileStart = Integer.parseInt(start); } } if (commandLine.hasOption("e")) { String end = commandLine.getOptionValue("e"); if (end != null && end.length() > 0) { csvFileEnd = Integer.parseInt(end); } } } System.out.println( "%%%%%%%%% csv ?, ?, ?(ms)," + new Date().getTime()); for (int i = csvFileStart; i <= csvFileEnd; i++) { new TestCase412RemoteMultiThreads(i).start(); } }
From source file:com.redhat.poc.jdg.bankofchina.performance.TestCase52RemoteMultiThreads.java
public static void main(String[] args) throws Exception { CommandLine commandLine; Options options = new Options(); options.addOption("n", true, "The read thread numbers option"); options.addOption("t", true, "The thread read times option"); BasicParser parser = new BasicParser(); parser.parse(options, args);/*from ww w . j a va 2 s .c om*/ commandLine = parser.parse(options, args); if (commandLine.getOptions().length > 0) { if (commandLine.hasOption("n")) { String numbers = commandLine.getOptionValue("n"); if (numbers != null && numbers.length() > 0) { writeThreadNumbers = Integer.parseInt(numbers); } } if (commandLine.hasOption("t")) { String times = commandLine.getOptionValue("t"); if (times != null && times.length() > 0) { threadWriteTimes = Integer.parseInt(times); } } } System.out.println(); System.out.println("%%%%%%%%% userid.csv %%%%%%%%%"); LoadUserIdList(); randomPoolSize = userIdList.size(); System.out.println( "%%%%%%%%% ? userid.csv , " + randomPoolSize + " ?? %%%%%%%%%"); randomPoolSizeByThread = randomPoolSize / writeThreadNumbers; System.out.println(); System.out.println( "%%%%%%%%% ?, " + writeThreadNumbers + ", , ??, " + threadWriteTimes + " ,?, ?(ms)," + new Date().getTime()); for (int i = 0; i < writeThreadNumbers; i++) { new TestCase52RemoteMultiThreads(i * randomPoolSizeByThread).start(); } }
From source file:com.redhat.poc.jdg.bankofchina.performance.TestCase51RemoteMultiThreads.java
public static void main(String[] args) throws Exception { CommandLine commandLine; Options options = new Options(); options.addOption("n", true, "The read thread numbers option"); options.addOption("t", true, "The thread read times option"); BasicParser parser = new BasicParser(); parser.parse(options, args);/*w w w. j a va 2s. c o m*/ commandLine = parser.parse(options, args); if (commandLine.getOptions().length > 0) { if (commandLine.hasOption("n")) { String numbers = commandLine.getOptionValue("n"); if (numbers != null && numbers.length() > 0) { readThreadNumbers = Integer.parseInt(numbers); } } if (commandLine.hasOption("t")) { String times = commandLine.getOptionValue("t"); if (times != null && times.length() > 0) { threadReadTimes = Integer.parseInt(times); } } } System.out.println(); System.out.println("%%%%%%%%% userid.csv %%%%%%%%%"); LoadUserIdList(); randomPoolSize = userIdList.size(); System.out.println( "%%%%%%%%% ? userid.csv , " + randomPoolSize + " ?? %%%%%%%%%"); randomPoolSizeByThread = randomPoolSize / readThreadNumbers; System.out.println(); System.out.println( "%%%%%%%%% ?, " + readThreadNumbers + " ,, ???, " + threadReadTimes + " ,?, ?(ms)," + new Date().getTime()); for (int i = 0; i < readThreadNumbers; i++) { new TestCase51RemoteMultiThreads(i * randomPoolSizeByThread).start(); } }