List of usage examples for org.apache.commons.cli Options Options
Options
From source file:net.forkwait.imageautomator.ImageAutomator.java
public static void main(String[] args) throws IOException { String inputImage = ""; Options options = new Options(); options.addOption("o", true, "output file name (e.g. thumb.jpg), default thumbnail.filename.ext"); options.addOption("q", true, "jpeg quality (e.g. 0.9, max 1.0), default 0.97"); options.addOption("s", true, "output max side length in px (e.g. 800), default 1200"); options.addOption("w", true, "watermark image file"); options.addOption("wt", true, "watermark transparency (e.g. 0.5, max 1.0), default 1.0"); options.addOption("wp", true, "watermark position (e.g. 0.9, max 1.0), default BOTTOM_RIGHT"); /*/*from ww w . j a v a2s . c o m*/ TOP_LEFT TOP_CENTER TOP_RIGHT CENTER_LEFT CENTER CENTER_RIGHT BOTTOM_LEFT BOTTOM_CENTER BOTTOM_RIGHT */ CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.getArgs().length < 1) { throw new ParseException("Too few arguments"); } else if (cmd.getArgs().length > 1) { throw new ParseException("Too many arguments"); } inputImage = cmd.getArgs()[0]; } catch (ParseException e) { showHelp(options, e.getLocalizedMessage()); System.exit(-1); } Thumbnails.Builder<File> st = Thumbnails.of(inputImage); if (cmd.hasOption("q")) { st.outputQuality(Double.parseDouble(cmd.getOptionValue("q"))); } else { st.outputQuality(0.97f); } if (cmd.hasOption("s")) { st.size(Integer.parseInt(cmd.getOptionValue("s")), Integer.parseInt(cmd.getOptionValue("s"))); } else { st.size(1200, 1200); } if (cmd.hasOption("w")) { Positions position = Positions.BOTTOM_RIGHT; float trans = 0.5f; if (cmd.hasOption("wp")) { position = Positions.valueOf(cmd.getOptionValue("wp")); } if (cmd.hasOption("wt")) { trans = Float.parseFloat(cmd.getOptionValue("wt")); } st.watermark(position, ImageIO.read(new File(cmd.getOptionValue("w"))), trans); } if (cmd.hasOption("o")) { st.toFile(new File(cmd.getOptionValue("o"))); } else { st.toFiles(Rename.PREFIX_DOT_THUMBNAIL); } //.outputFormat("jpg") System.exit(0); }
From source file:cc.twittertools.index.ExtractTweetidsFromCollection.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory") .create(COLLECTION_OPTION)); CommandLine cmdline = null;//from w ww . j a v a 2s. c o m CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(COLLECTION_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ExtractTweetidsFromCollection.class.getName(), options); System.exit(-1); } String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION); File file = new File(collectionPath); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } StatusStream stream = new JsonStatusCorpusReader(file); Status status; while ((status = stream.next()) != null) { System.out.println(status.getId() + "\t" + status.getScreenname()); } }
From source file:com.rabbitmq.examples.FileProducer.java
public static void main(String[] args) { Options options = new Options(); options.addOption(new Option("h", "uri", true, "AMQP URI")); options.addOption(new Option("p", "port", true, "broker port")); options.addOption(new Option("t", "type", true, "exchange type")); options.addOption(new Option("e", "exchange", true, "exchange name")); options.addOption(new Option("k", "routing-key", true, "routing key")); CommandLineParser parser = new GnuParser(); try {/*from w w w. ja va 2 s. c o m*/ CommandLine cmd = parser.parse(options, args); String uri = strArg(cmd, 'h', "amqp://localhost"); String exchangeType = strArg(cmd, 't', "direct"); String exchange = strArg(cmd, 'e', null); String routingKey = strArg(cmd, 'k', null); ConnectionFactory connFactory = new ConnectionFactory(); connFactory.setUri(uri); Connection conn = connFactory.newConnection(); final Channel ch = conn.createChannel(); if (exchange == null) { System.err.println("Please supply exchange name to send to (-e)"); System.exit(2); } if (routingKey == null) { System.err.println("Please supply routing key to send to (-k)"); System.exit(2); } ch.exchangeDeclare(exchange, exchangeType); for (String filename : cmd.getArgs()) { System.out.print("Sending " + filename + "..."); File f = new File(filename); FileInputStream i = new FileInputStream(f); byte[] body = new byte[(int) f.length()]; i.read(body); i.close(); Map<String, Object> headers = new HashMap<String, Object>(); headers.put("filename", filename); headers.put("length", (int) f.length()); BasicProperties props = new BasicProperties.Builder().headers(headers).build(); ch.basicPublish(exchange, routingKey, props, body); System.out.println(" done."); } conn.close(); } catch (Exception ex) { System.err.println("Main thread caught exception: " + ex); ex.printStackTrace(); System.exit(1); } }
From source file:com.google.api.codegen.DiscoveryFragmentGeneratorTool.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("h", "help", false, "show usage"); options.addOption(Option.builder().longOpt("discovery_doc") .desc("The Discovery doc representing the service description.").hasArg().argName("DISCOVERY-DOC") .required(true).build());//from ww w . j a va2 s .co m options.addOption(Option.builder().longOpt("overrides").desc("The path to the sample config overrides file") .hasArg().argName("OVERRIDES").build()); options.addOption(Option.builder().longOpt("gapic_yaml").desc("The GAPIC YAML configuration file or files.") .hasArg().argName("GAPIC-YAML").required(true).build()); options.addOption(Option.builder("o").longOpt("output") .desc("The directory in which to output the generated fragments.").hasArg() .argName("OUTPUT-DIRECTORY").build()); options.addOption(Option.builder().longOpt("auth_instructions") .desc("An @-delimited map of language to auth instructions URL: lang:URL@lang:URL@...").hasArg() .argName("AUTH-INSTRUCTIONS").build()); CommandLine cl = (new DefaultParser()).parse(options, args); if (cl.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp("CodeGeneratorTool", options); } generate(cl.getOptionValue("discovery_doc"), cl.getOptionValues("gapic_yaml"), cl.getOptionValue("overrides", ""), cl.getOptionValue("output", ""), cl.getOptionValue("auth_instructions", "")); }
From source file:RedPenRunner.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("h", "help", false, "help"); options.addOption("v", "version", false, "print the version information and exit"); OptionBuilder.withLongOpt("port"); OptionBuilder.withDescription("port number"); OptionBuilder.hasArg();//from w w w.j a v a 2 s. c om OptionBuilder.withArgName("PORT"); options.addOption(OptionBuilder.create("p")); OptionBuilder.withLongOpt("key"); OptionBuilder.withDescription("stop key"); OptionBuilder.hasArg(); OptionBuilder.withArgName("STOP_KEY"); options.addOption(OptionBuilder.create("k")); OptionBuilder.withLongOpt("conf"); OptionBuilder.withDescription("configuration file"); OptionBuilder.hasArg(); OptionBuilder.withArgName("CONFIG_FILE"); options.addOption(OptionBuilder.create("c")); OptionBuilder.withLongOpt("lang"); OptionBuilder.withDescription("Language of error messages"); OptionBuilder.hasArg(); OptionBuilder.withArgName("LANGUAGE"); options.addOption(OptionBuilder.create("L")); CommandLineParser parser = new BasicParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (Exception e) { printHelp(options); System.exit(-1); } int portNum = 8080; String language = "en"; if (commandLine.hasOption("h")) { printHelp(options); System.exit(0); } if (commandLine.hasOption("v")) { System.out.println(RedPen.VERSION); System.exit(0); } if (commandLine.hasOption("p")) { portNum = Integer.parseInt(commandLine.getOptionValue("p")); } if (commandLine.hasOption("L")) { language = commandLine.getOptionValue("L"); } if (isPortTaken(portNum)) { System.err.println("port is taken..."); System.exit(1); } // set language if (language.equals("ja")) { Locale.setDefault(new Locale("ja", "JA")); } else { Locale.setDefault(new Locale("en", "EN")); } final String contextPath = System.getProperty("redpen.home", "/"); Server server = new Server(portNum); ProtectionDomain domain = RedPenRunner.class.getProtectionDomain(); URL location = domain.getCodeSource().getLocation(); HandlerList handlerList = new HandlerList(); if (commandLine.hasOption("key")) { // Add Shutdown handler only when STOP_KEY is specified ShutdownHandler shutdownHandler = new ShutdownHandler(commandLine.getOptionValue("key")); handlerList.addHandler(shutdownHandler); } WebAppContext webapp = new WebAppContext(); webapp.setContextPath(contextPath); if (location.toExternalForm().endsWith("redpen-server/target/classes/")) { // use redpen-server/target/redpen-server instead, because target/classes doesn't contain web resources. webapp.setWar(location.toExternalForm() + "../redpen-server/"); } else { webapp.setWar(location.toExternalForm()); } if (commandLine.hasOption("c")) { webapp.setInitParameter("redpen.conf.path", commandLine.getOptionValue("c")); } handlerList.addHandler(webapp); server.setHandler(handlerList); server.start(); server.join(); }
From source file:com.google.cloud.monitoring.v3.MetricServiceSmokeTest.java
public static void main(String args[]) { Logger.getLogger("").setLevel(Level.WARNING); try {// w w w. ja v a2 s . co m Options options = new Options(); options.addOption("h", "help", false, "show usage"); options.addOption(Option.builder().longOpt("project_id").desc("Project id").hasArg() .argName("PROJECT-ID").required(true).build()); CommandLine cl = (new DefaultParser()).parse(options, args); if (cl.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp("MetricServiceSmokeTest", options); } executeNoCatch(cl.getOptionValue("project_id")); System.out.println("OK"); } catch (Exception e) { System.err.println("Failed with exception:"); e.printStackTrace(System.err); System.exit(1); } }
From source file:de.thomasvolk.genexample.GenAlg.java
public static void main(String[] args) throws IOException, ParseException { System.out.println("Genetische Algorithmen"); Options options = new Options(); options.addOption(option("s", "Jede s Generation wird im Bericht ausgegeben")); options.addOption(option("w", "Quelldatei Wagon")); options.addOption(option("l", "Quelldatei Passagierliste")); options.addOption(option("d", "Zielverzeichnis Bericht")); options.addOption(option("a", "Algorithmus Typ " + Arrays.asList(AlgorithmusTyp.values()).toString())); options.addOption(option("g", "Anzahl der Generationen")); options.addOption(option("p", "Anzahl der Populationen")); options.addOption("h", false, "Hilfe"); CommandLineParser parser = new PosixParser(); try {/*from w w w .j a v a2 s .co m*/ CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h')) { printUsage(options); System.exit(0); } int generationen = getNummer(options, cmd.getOptionValue('g'), 2000); int populationen = getNummer(options, cmd.getOptionValue('p'), 20); int schritte = getNummer(options, cmd.getOptionValue('s'), 100); AlgorithmusTyp[] alg = AlgorithmusTyp.values(); if (cmd.hasOption('a')) { try { alg = new AlgorithmusTyp[] { AlgorithmusTyp.valueOf(cmd.getOptionValue('a')) }; } catch (IllegalArgumentException e) { printErrorAndExit(e, options); } } String reportDir = cmd.getOptionValue('d'); reportDir = StringUtils.isBlank(reportDir) ? "report" : reportDir; String wagonDatei = cmd.getOptionValue('w'); String passagierDatei = cmd.getOptionValue('l'); if (wagonDatei == null) { wagonDatei = erzeugeBeispielDatei("wagon.txt"); } if (passagierDatei == null) { passagierDatei = erzeugeBeispielDatei("passagiere.csv"); } System.out.println("Wagon Datein: " + wagonDatei); System.out.println("Passagier Datei: " + passagierDatei); System.out.println("Bericht: " + new File(reportDir).getAbsolutePath()); System.out.println("Anzahl Generationen: " + generationen); System.out.println("Anzahl Populationen: " + populationen); System.out.printf("Protokolliere jede %dte Generation im Bericht\n", schritte); WagonFactory wagonFactory = new WagonFactory(); PassagierFactory passagierFactory = new CSVPassagierFactory(); GenAlg genAlg = new GenAlg(wagonFactory, passagierFactory); genAlg.run(alg, passagierDatei, wagonDatei, reportDir, schritte, generationen, populationen); } catch (ParseException e) { printErrorAndExit(e, options); } }
From source file:com.aestel.chemistry.openEye.fp.FPDictionarySorter.java
public static void main(String... args) throws IOException { long start = System.currentTimeMillis(); int iCounter = 0; int fpCounter = 0; // create command line Options object Options options = new Options(); Option opt = new Option("i", true, "input file [.ism,.sdf,...]"); opt.setRequired(true);//from w w w. ja va 2s .c om options.addOption(opt); opt = new Option("fpType", true, "fingerPrintType: maccs|linear7|linear7*4"); opt.setRequired(true); options.addOption(opt); opt = new Option("sampleFract", true, "fraction of input molecules to use (Default=1)"); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } if (args.length != 0) { exitWithHelp(options); } String type = cmd.getOptionValue("fpType"); boolean updateDictionaryFile = false; boolean hashUnknownFrag = false; Fingerprinter fprinter = Fingerprinter.createFingerprinter(type, updateDictionaryFile, hashUnknownFrag); OEMolBase mol = new OEGraphMol(); String inFile = cmd.getOptionValue("i"); oemolistream ifs = new oemolistream(inFile); double fract = 2D; String tmp = cmd.getOptionValue("sampleFract"); if (tmp != null) fract = Double.parseDouble(tmp); Random rnd = new Random(); LearningStrcutureCodeMapper mapper = (LearningStrcutureCodeMapper) fprinter.getMapper(); int dictSize = mapper.getMaxIdx() + 1; int[] freq = new int[dictSize]; while (oechem.OEReadMolecule(ifs, mol)) { iCounter++; if (rnd.nextDouble() < fract) { fpCounter++; Fingerprint fp = fprinter.getFingerprint(mol); for (int bit : fp.getBits()) freq[bit]++; } if (iCounter % 100 == 0) System.err.print("."); if (iCounter % 4000 == 0) { System.err.printf(" %d %d %dsec\n", iCounter, fpCounter, (System.currentTimeMillis() - start) / 1000); } } System.err.printf("FPDictionarySorter: Read %d structures calculated %d fprints in %d sec\n", iCounter, fpCounter, (System.currentTimeMillis() - start) / 1000); mapper.reSortDictionary(freq); mapper.writeDictionary(); fprinter.close(); }
From source file:it.anyplace.sync.relay.server.Main.java
public static void main(String[] args) throws ParseException, Exception { Options options = new Options(); options.addOption("r", "relay-server", true, "set relay server to serve for"); options.addOption("p", "port", true, "set http server port"); options.addOption("h", "help", false, "print help"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("s-client", options); return;/* ww w .j av a 2 s . c o m*/ } int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 22080; String relayServer = firstNonNull(emptyToNull(cmd.getOptionValue("r")), "relay://localhost"); logger.info("starting http relay server :{} for relay server {}", port, relayServer); HttpRelayServer httpRelayServer = new HttpRelayServer( DeviceAddress.newBuilder().setDeviceId("relay").setAddress(relayServer).build().getSocketAddress()); httpRelayServer.start(port); httpRelayServer.join(); }
From source file:example.HelloConsole.java
public static void main(String[] args) throws Exception { Option msg = Option.builder("m").longOpt("message").hasArg().desc("the message to capitalize").build(); Options options = new Options(); options.addOption(msg);/*from ww w. j a va 2 s.co m*/ CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(options, args); String message = line.getOptionValue("m", "Hello Ivy!"); System.out.println("standard message : " + message); System.out.println( "capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message)); }