List of usage examples for org.apache.commons.cli Options addOption
public Options addOption(String opt, boolean hasArg, String description)
From source file:havocx42.Program.java
public static void main(String[] args) throws ParseException { try {/*from ww w . j av a 2s .c o m*/ initRootLogger(); } catch (SecurityException | IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return; } try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e1) { LOGGER.log(Level.WARNING, "Unable to set Look and Feel", e1); } Options options = new Options(); options.addOption("nogui", false, "run as a command line tool, must also supply -target and -source arguments"); options.addOption("source", true, "source directory where the PR weapons folder has been extracted"); options.addOption("target", true, "target file to write to"); options.addOption("version", false, "print the version information and exit"); options.addOption("help", false, "print this message"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("version")) { System.out.println("PRStats " + VERSION); System.out.println("Written by havocx42"); return; } if ((cmd.hasOption("nogui") && (!cmd.hasOption("source") || !cmd.hasOption("target"))) || cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("PRStats", options); return; } final String target; final String source; source = cmd.getOptionValue("source"); target = cmd.getOptionValue("target"); LOGGER.info("Source Argument: " + source); LOGGER.info("Target Argument: " + target); if (!cmd.hasOption("nogui")) { EventQueue.invokeLater(new Runnable() { @SuppressWarnings("unused") public void run() { try { Gui window = new Gui(source, target); } catch (Exception e) { e.printStackTrace(); } } }); return; } File targetFile = new File(target); File sourceFile = new File(source); Controller controller = new Controller(); controller.run(sourceFile, targetFile); }
From source file:com.cohesionforce.AvroToParquet.java
public static void main(String[] args) { String inputFile = null;/*from w w w . j a v a 2 s . com*/ String outputFile = null; HelpFormatter formatter = new HelpFormatter(); // create Options object Options options = new Options(); // add t option options.addOption("i", true, "input avro file"); options.addOption("o", true, "ouptut Parquet file"); CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(options, args); inputFile = cmd.getOptionValue("i"); if (inputFile == null) { formatter.printHelp("AvroToParquet", options); return; } outputFile = cmd.getOptionValue("o"); } catch (ParseException exc) { System.err.println("Problem with command line parameters: " + exc.getMessage()); return; } File avroFile = new File(inputFile); if (!avroFile.exists()) { System.err.println("Could not open file: " + inputFile); return; } try { DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>(); DataFileReader<GenericRecord> dataFileReader; dataFileReader = new DataFileReader<GenericRecord>(avroFile, datumReader); Schema avroSchema = dataFileReader.getSchema(); // choose compression scheme CompressionCodecName compressionCodecName = CompressionCodecName.SNAPPY; // set Parquet file block size and page size values int blockSize = 256 * 1024 * 1024; int pageSize = 64 * 1024; String base = FilenameUtils.removeExtension(avroFile.getAbsolutePath()) + ".parquet"; if (outputFile != null) { File file = new File(outputFile); base = file.getAbsolutePath(); } Path outputPath = new Path("file:///" + base); // the ParquetWriter object that will consume Avro GenericRecords ParquetWriter<GenericRecord> parquetWriter; parquetWriter = new AvroParquetWriter<GenericRecord>(outputPath, avroSchema, compressionCodecName, blockSize, pageSize); for (GenericRecord record : dataFileReader) { parquetWriter.write(record); } dataFileReader.close(); parquetWriter.close(); } catch (IOException e) { System.err.println("Caught exception: " + e.getMessage()); } }
From source file:me.cavar.pg2tei.Gutenberg2TEI.java
/** * @param args/*from w w w. j ava 2 s . c o m*/ */ public static void main(String[] args) { // Process command line Options options = new Options(); options.addOption("c", true, "Catalogue URL"); options.addOption("o", true, "Output folder"); // options.addOption("f", true, "Resulting output catalogue file name"); options.addOption("h", false, "Help"); // the individual RDF-files are at this URL: // The RDF-file name is this.idN + ".rdf" String ebookURLStr = "http://www.gutenberg.org/ebooks/"; // the URL to the catalog.rdf String catalogURLStr = "http://www.gutenberg.org/feeds/catalog.rdf.zip"; String outputFolder = "."; String catalogOutFN = "catalog.rdf"; CommandLineParser parser; parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { System.out.println("Project Gutenberg fetch RDF catalog, HTML-files and generate TEI XML"); System.out.println(""); return; } if (cmd.hasOption("c")) { catalogURLStr = cmd.getOptionValue("c"); } if (cmd.hasOption("o")) { outputFolder = cmd.getOptionValue("o"); } //if (cmd.hasOption("f")) { // catalogOutFN = cmd.getOptionValue("f"); //} } catch (ParseException ex) { System.out.println("Command line argument error:" + ex.getMessage()); } // Do the fetching of the RDF catalog fetchRDF(catalogURLStr, outputFolder, catalogOutFN); // process the RDF file processRDF(outputFolder, catalogOutFN, ebookURLStr); }
From source file:StompMessagePublisher.java
public static void main(String[] args) throws ParseException { Options options = new Options(); options.addOption("h", true, "Host to connect to"); options.addOption("p", true, "Port to connect to"); options.addOption("u", true, "User name"); options.addOption("P", true, "Password"); options.addOption("d", true, "JMS Destination"); options.addOption("j", true, "JSON to send"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); // String host = "loyjbsms11-public.lolacloud.com"; // String host = "pink.cloudtroopers.ro"; String host = "localhost"; // String host = "pink.cloudtroopers.ro"; String port = "61613"; String user = "guest"; String pass = "P@ssword1"; // String destination = REWARD_POINTS_JMS_DESTINATION; // String json = REWARD_POINTS_JSON_MERGE; String destination = MEMBER_REGISTRATION_JMS_DESTINATION; String json = MEMBER_REGISTRATION_JSON; if (cmd.hasOption("h")) { host = cmd.getOptionValue("h"); }/*from ww w . j a v a2s .c o m*/ if (cmd.hasOption("p")) { port = cmd.getOptionValue("p"); } if (cmd.hasOption("u")) { user = cmd.getOptionValue("u"); } if (cmd.hasOption("P")) { pass = cmd.getOptionValue("P"); } if (cmd.hasOption("d")) { destination = cmd.getOptionValue("d"); } if (cmd.hasOption("j")) { json = cmd.getOptionValue("j"); } try { StompConnection connection = new StompConnection(); connection.open(host, Integer.parseInt(port)); connection.connect(user, pass); for (int i = 0; i < 1; i++) { System.out.println(" msg " + i); String newJson = json.replaceAll("" + EXTERNAL_PROVIDER_ID, "" + (EXTERNAL_PROVIDER_ID + i)); newJson = newJson.replaceAll("" + CUSTOMER_ACCT_ID, "" + (CUSTOMER_ACCT_ID + i)); newJson = newJson.replaceAll("" + LOYALTY_ACCT_ID, "" + (LOYALTY_ACCT_ID + i)); send(host, port, user, pass, destination, newJson, connection); } connection.disconnect(); connection.close(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:io.github.gsteckman.doorcontroller.INA219Util.java
/** * Reads the Current from the INA219 with an I2C address and for a duration specified on the command line. * // w ww .j a va 2 s. c o m * @param args * Command line arguments. * @throws IOException * If an error occurs reading/writing to the INA219 * @throws ParseException * If the command line arguments could not be parsed. */ public static void main(String[] args) throws IOException, ParseException { Options options = new Options(); options.addOption("addr", true, "I2C Address"); options.addOption("d", true, "Acquisition duration, in seconds"); options.addOption("bv", false, "Also read bus voltage"); options.addOption("sv", false, "Also read shunt voltage"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); Address addr = Address.ADDR_40; if (cmd.hasOption("addr")) { int opt = Integer.parseInt(cmd.getOptionValue("addr"), 16); Address a = Address.getAddress(opt); if (a != null) { addr = a; } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("INA219Util", options); return; } } int duration = 0; if (cmd.hasOption("d")) { String opt = cmd.getOptionValue("d"); duration = Integer.parseInt(opt); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("INA219Util", options); return; } boolean readBusVoltage = false; if (cmd.hasOption("bv")) { readBusVoltage = true; } boolean readShuntVoltage = false; if (cmd.hasOption("sv")) { readShuntVoltage = true; } INA219 i219 = new INA219(addr, 0.1, 3.2, INA219.Brng.V16, INA219.Pga.GAIN_8, INA219.Adc.BITS_12, INA219.Adc.SAMPLES_128); System.out.printf("Time\tCurrent"); if (readBusVoltage) { System.out.printf("\tBus"); } if (readShuntVoltage) { System.out.printf("\tShunt"); } System.out.printf("\n"); long start = System.currentTimeMillis(); do { try { System.out.printf("%d\t%f", System.currentTimeMillis() - start, i219.getCurrent()); if (readBusVoltage) { System.out.printf("\t%f", i219.getBusVoltage()); } if (readShuntVoltage) { System.out.printf("\t%f", i219.getShuntVoltage()); } System.out.printf("\n"); Thread.sleep(100); } catch (IOException e) { LOG.error("Exception while reading I2C bus", e); } catch (InterruptedException e) { break; } } while (System.currentTimeMillis() - start < duration * 1000); }
From source file:de.jackwhite20.japs.server.Main.java
public static void main(String[] args) throws Exception { Config config = null;// w w w .j av a2 s . c o m if (args.length > 0) { Options options = new Options(); options.addOption("h", true, "Address to bind to"); options.addOption("p", true, "Port to bind to"); options.addOption("b", true, "The backlog"); options.addOption("t", true, "Worker thread count"); options.addOption("d", false, "If debug is enabled or not"); options.addOption("c", true, "Add server as a cluster"); options.addOption("ci", true, "Sets the cache check interval"); options.addOption("si", true, "Sets the snapshot interval"); CommandLineParser commandLineParser = new BasicParser(); CommandLine commandLine = commandLineParser.parse(options, args); if (commandLine.hasOption("h") && commandLine.hasOption("p") && commandLine.hasOption("b") && commandLine.hasOption("t")) { List<ClusterServer> clusterServers = new ArrayList<>(); if (commandLine.hasOption("c")) { for (String c : commandLine.getOptionValues("c")) { String[] splitted = c.split(":"); clusterServers.add(new ClusterServer(splitted[0], Integer.parseInt(splitted[1]))); } } config = new Config(commandLine.getOptionValue("h"), Integer.parseInt(commandLine.getOptionValue("p")), Integer.parseInt(commandLine.getOptionValue("b")), commandLine.hasOption("d"), Integer.parseInt(commandLine.getOptionValue("t")), clusterServers, (commandLine.hasOption("ci")) ? Integer.parseInt(commandLine.getOptionValue("ci")) : 300, (commandLine.hasOption("si")) ? Integer.parseInt(commandLine.getOptionValue("si")) : -1); } else { System.out.println( "Usage: java -jar japs-server.jar -h <Host> -p <Port> -b <Backlog> -t <Threads> [-c IP:Port IP:Port] [-d]"); System.out.println( "Example (with debugging enabled): java -jar japs-server.jar -h localhost -p 1337 -b 100 -t 4 -d"); System.out.println( "Example (with debugging enabled and cluster setup): java -jar japs-server.jar -h localhost -p 1337 -b 100 -t 4 -c localhost:1338 -d"); System.exit(-1); } } else { File configFile = new File("config.json"); if (!configFile.exists()) { try { Files.copy(JaPS.class.getClassLoader().getResourceAsStream("config.json"), configFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { System.err.println("Unable to load default config!"); System.exit(-1); } } try { config = new Gson().fromJson( Files.lines(configFile.toPath()).map(String::toString).collect(Collectors.joining(" ")), Config.class); } catch (IOException e) { System.err.println("Unable to load 'config.json' in current directory!"); System.exit(-1); } } if (config == null) { System.err.println("Failed to create a Config!"); System.err.println("Please check the program parameters or the 'config.json' file!"); } else { System.err.println("Using Config: " + config); JaPS jaPS = new JaPS(config); jaPS.init(); jaPS.start(); jaPS.stop(); } }
From source file:de.akquinet.dustjs.DustEngine.java
public static void main(String[] args) throws URISyntaxException { Options cmdOptions = new Options(); cmdOptions.addOption(DustOptions.CHARSET_OPTION, true, "Input file charset encoding. Defaults to UTF-8."); cmdOptions.addOption(DustOptions.DUST_OPTION, true, "Path to a custom dust.js for Rhino version."); try {//from ww w . j a v a2s.co m CommandLineParser cmdParser = new GnuParser(); CommandLine cmdLine = cmdParser.parse(cmdOptions, args); DustOptions options = new DustOptions(); if (cmdLine.hasOption(DustOptions.CHARSET_OPTION)) { options.setCharset(cmdLine.getOptionValue(DustOptions.CHARSET_OPTION)); } if (cmdLine.hasOption(DustOptions.DUST_OPTION)) { options.setDust(new File(cmdLine.getOptionValue(DustOptions.DUST_OPTION)).toURI().toURL()); } DustEngine engine = new DustEngine(options); String[] files = cmdLine.getArgs(); String src = null; if (files == null || files.length == 0) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringWriter sw = new StringWriter(); char[] buffer = new char[1024]; int n = 0; while (-1 != (n = in.read(buffer))) { sw.write(buffer, 0, n); } src = sw.toString(); } if (src != null && !src.isEmpty()) { System.out.println(engine.compile(src, "test")); return; } if (files.length == 1) { System.out.println(engine.compile(new File(files[0]))); return; } if (files.length == 2) { engine.compile(new File(files[0]), new File(files[1])); return; } } catch (IOException ioe) { System.err.println("Error opening input file."); } catch (ParseException pe) { System.err.println("Error parsing arguments."); } HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar dust-engine.jar input [output] [options]", cmdOptions); System.exit(1); }
From source file:knowledgeMiner.InformationDripBootstrapping.java
public static void main(String[] args) { Options options = new Options(); options.addOption("r", true, "The number of ripples (-1 for unlimited)."); options.addOption("c", true, "The concept to begin with (\"article\" or #concept)."); options.addOption("N", true, "The initial hashmap size for the nodes."); options.addOption("i", true, "Initial run number."); CommandLineParser parser = new BasicParser(); try {/*from ww w.j a v a2 s .c o m*/ CommandLine parse = parser.parse(options, args); InformationDripBootstrapping rb = new InformationDripBootstrapping(parse.getOptionValue("c"), parse.getOptionValue("r"), parse.getOptionValue("N"), parse.getOptionValue("i")); rb.run(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
From source file:com.redhat.poc.jdg.bankofchina.function.TestCase411RemoteMultiThreadsCustomMarshal.java
public static void main(String[] args) throws Exception { CommandLine commandLine;//from w w w. j a v a2 s .co m 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); 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 TestCase411RemoteMultiThreadsCustomMarshal(i).start(); } }
From source file:com.dattack.dbping.cli.PingAnalyzerCli.java
/** * The <code>main</code> method. * * @param args// w ww . j a v a 2 s .com * the program arguments */ public static void main(final String[] args) { try { // create Options object final Options options = new Options(); // add t option options.addOption(START_DATE_OPTION, true, "the date for an analysis run to begin"); options.addOption(END_DATE_OPTION, true, "the date for an analysis run to finish"); options.addOption(SPAN_OPTION, true, "the period of time between points"); options.addOption(DATA_FILE_OPTION, true, "the data file to analyze"); options.addOption(METRIC_OPTION, true, "the metric to analyze"); options.addOption(MAX_VALUE_OPTION, true, "the maximum value to use"); options.addOption(MIN_VALUE_OPTION, true, "the minimum value to use"); final CommandLineParser parser = new DefaultParser(); final CommandLine cmd = parser.parse(options, args); final ReportContext context = new ReportContext(); context.setStartDate(TimeUtils.parseDate(cmd.getOptionValue(START_DATE_OPTION))); context.setEndDate(TimeUtils.parseDate(cmd.getOptionValue(END_DATE_OPTION))); context.setTimeSpan(TimeUtils.parseTimeSpanMillis(cmd.getOptionValue(SPAN_OPTION))); context.setMaxValue(parseLong(cmd.getOptionValue(MAX_VALUE_OPTION))); context.setMinValue(parseLong(cmd.getOptionValue(MIN_VALUE_OPTION))); if (cmd.hasOption(METRIC_OPTION)) { for (final String metricName : cmd.getOptionValues(METRIC_OPTION)) { context.addMetricNameFilter(MetricName.parse(metricName)); } } final PingAnalyzerCli ping = new PingAnalyzerCli(); for (final String file : cmd.getOptionValues(DATA_FILE_OPTION)) { ping.execute(new File(file), context); } } catch (final ParseException | ConfigurationException e) { System.err.println(e.getMessage()); } }