List of usage examples for org.apache.commons.cli HelpFormatter HelpFormatter
HelpFormatter
From source file:edu.umd.cloud9.example.bigram.AnalyzeBigramRelativeFrequencyTuple.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); CommandLine cmdline = null;//w w w . ja v a2 s . 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(INPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(AnalyzeBigramRelativeFrequencyJson.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String inputPath = cmdline.getOptionValue(INPUT); System.out.println("input path: " + inputPath); List<PairOfWritables<Tuple, FloatWritable>> pairs = SequenceFileUtils.readDirectory(new Path(inputPath)); List<PairOfWritables<Tuple, FloatWritable>> list1 = Lists.newArrayList(); List<PairOfWritables<Tuple, FloatWritable>> list2 = Lists.newArrayList(); for (PairOfWritables<Tuple, FloatWritable> p : pairs) { Tuple bigram = p.getLeftElement(); if (bigram.get(0).equals("light")) { list1.add(p); } if (bigram.get(0).equals("contain")) { list2.add(p); } } Collections.sort(list1, new Comparator<PairOfWritables<Tuple, FloatWritable>>() { @SuppressWarnings("unchecked") public int compare(PairOfWritables<Tuple, FloatWritable> e1, PairOfWritables<Tuple, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Iterator<PairOfWritables<Tuple, FloatWritable>> iter1 = Iterators.limit(list1.iterator(), 10); while (iter1.hasNext()) { PairOfWritables<Tuple, FloatWritable> p = iter1.next(); Tuple bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); } Collections.sort(list2, new Comparator<PairOfWritables<Tuple, FloatWritable>>() { @SuppressWarnings("unchecked") public int compare(PairOfWritables<Tuple, FloatWritable> e1, PairOfWritables<Tuple, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Iterator<PairOfWritables<Tuple, FloatWritable>> iter2 = Iterators.limit(list2.iterator(), 10); while (iter2.hasNext()) { PairOfWritables<Tuple, FloatWritable> p = iter2.next(); Tuple bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); } }
From source file:com.ibm.rdf.store.sparql11.DB2RDFQuery.java
public static void main(String[] args) { Options options = new Options(); try {// www . ja v a2 s. c o m // create Options object options.addOption("jdbcurl", true, "jdbc url"); options.addOption("schema", true, "schema name"); options.addOption("kb", true, "knowledge base"); options.addOption("username", true, "db user name"); options.addOption("password", true, "db password"); options.addOption("queryFile", true, "query file"); options.addOption("defaultUnionGraph", false, "default Union Graph semantics"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); boolean defUnion = cmd.hasOption("defaultUnionGraph") ? Boolean.parseBoolean(cmd.getOptionValue("defaultUnionGraph")) : false; DB2TestData data = new DB2TestData(cmd.getOptionValue("jdbcurl"), cmd.getOptionValue("kb"), cmd.getOptionValue("username"), cmd.getOptionValue("password"), cmd.getOptionValue("schemaName"), defUnion); DB2RDFQuery q = new DB2RDFQuery(new DB2Engine(), data); q.executeQuery(cmd.getOptionValue("queryFile")); } catch (Exception e) { e.printStackTrace(); HelpFormatter help = new HelpFormatter(); help.printHelp("DB2RDFQuery", options); } }
From source file:com.github.braully.graph.UtilResultMerge.java
public static void main(String... args) throws Exception { Options options = new Options(); Option input = new Option("i", "input", true, "input file path"); input.setRequired(false);/*from ww w .j a va2 s . c o m*/ options.addOption(input); Option output = new Option("o", "output", true, "output file"); output.setRequired(false); options.addOption(output); Option verb = new Option("v", "verbose", false, "verbose"); output.setRequired(false); options.addOption(verb); Option exluces = new Option("x", "exclude", true, "exclude operations"); exluces.setRequired(false); options.addOption(exluces); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("UtilResult", options); System.exit(1); return; } String[] excludes = cmd.getOptionValues("exclude"); String[] inputs = cmd.getOptionValues("input"); if (inputs == null) { inputs = new String[] { "/home/strike/Dropbox/workspace/graph-caratheodory-np3/grafos-processamento/Almost_hypohamiltonian" // "/media/dados/documentos/grafos-processamento/Almost_hypohamiltonian", // "/home/strike/Documentos/grafos-processamento/Cubic", // "/home/strike/Documentos/grafos-processamento/Critical_H-free", // "/home/strike/Documentos/grafos-processamento/Highly_irregular", // "/home/strike/Documentos/grafos-processamento/Hypohamiltonian_graphs", // "/home/strike/Documentos/grafos-processamento/Maximal_triangle-free", // "/home/strike/Documentos/grafos-processamento/Minimal_Ramsey", // "/home/strike/Documentos/grafos-processamento/Strongly_regular", // "/home/strike/Documentos/grafos-processamento/Vertex-transitive", // "/home/strike/Documentos/grafos-processamento/Trees" }; excludes = new String[] { "carathe" }; verbose = true; } if (cmd.hasOption(verb.getOpt())) { verbose = true; } if (inputs != null) { processInputs(inputs, excludes); } }
From source file:PlyBounder.java
public static void main(String[] args) { // Get the commandline arguments Options options = new Options(); // Available options Option plyPath = OptionBuilder.withArgName("dir").hasArg() .withDescription("directory containing input .ply files").create("plyPath"); Option boundingbox = OptionBuilder.withArgName("string").hasArg() .withDescription("bounding box in WKT notation").create("boundingbox"); Option outputPlyFile = OptionBuilder.withArgName("file").hasArg().withDescription("output PLY file name") .create("outputPlyFile"); options.addOption(plyPath);//www.ja v a2 s .c o m options.addOption(boundingbox); options.addOption(outputPlyFile); String plydir = "."; String boundingboxstr = ""; String outputfilename = ""; CommandLineParser parser = new DefaultParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); boundingboxstr = line.getOptionValue("boundingbox"); outputfilename = line.getOptionValue("outputPlyFile"); if (line.hasOption("plyPath")) { // print the value of block-size plydir = line.getOptionValue("plyPath"); System.out.println("Using plyPath=" + plydir); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("PlyBounder", options); } //System.out.println( "plyPath=" + line.getOptionValue( "plyPath" ) ); } catch (ParseException exp) { System.err.println("Error getting arguments: " + exp.getMessage()); } // input directory // Get list of files File dir = new File(plydir); //System.out.println("Getting all files in " + dir.getCanonicalPath()); List<File> files = (List<File>) FileUtils.listFiles(dir, new String[] { "ply", "PLY" }, false); for (File file : files) { try { System.out.println("file=" + file.getCanonicalPath()); } catch (IOException e) { e.printStackTrace(); } } String sometempfile = "magweg.wkt"; String s = null; // Loop through .ply files in directory for (File file : files) { try { String cmdl[] = { "./ply-tool.py", "intersection", file.getCanonicalPath(), boundingboxstr, sometempfile }; //System.out.println("Running: " + Arrays.toString(cmdl)); Process p = Runtime.getRuntime().exec(cmdl); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); // read the output from the command System.out.println("cmdout:\n"); while ((s = stdInput.readLine()) != null) { System.out.println(s); } // read any errors from the attempted command System.out.println("cmderr:\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); } } catch (IOException e) { e.printStackTrace(); } } // Write new .ply file //ply-tool write setfile outputPlyFile try { String cmdl = "./ply-tool.py write " + sometempfile + " " + outputfilename; System.out.println("Running: " + cmdl); Process p = Runtime.getRuntime().exec(cmdl); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); // read the output from the command System.out.println("cmdout:\n"); while ((s = stdInput.readLine()) != null) { System.out.println(s); } // read any errors from the attempted command System.out.println("cmderr:\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); } } catch (IOException e) { e.printStackTrace(); } // Done System.out.println("Done"); }
From source file:com.artistech.tuio.mouse.ZeroMqMouse.java
/** * Main entry point for ZeroMQ integration. * * @param args//from w w w . j a v a 2s .com * @throws AWTException * @throws java.io.IOException */ public static void main(String[] args) throws AWTException, java.io.IOException { //read off the TUIO port from the command line String zeromq_port; Options options = new Options(); options.addOption("z", "zeromq-port", true, "ZeroMQ Server:Port to subscribe to. (-z localhost:5565)"); options.addOption("h", "help", false, "Show this message."); HelpFormatter formatter = new HelpFormatter(); try { CommandLineParser parser = new org.apache.commons.cli.BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { formatter.printHelp("tuio-mouse-driver", options); return; } else { if (cmd.hasOption("z") || cmd.hasOption("zeromq-port")) { zeromq_port = cmd.getOptionValue("z"); } else { System.err.println("The zeromq-port value must be specified."); formatter.printHelp("tuio-mouse-driver", options); return; } } } catch (ParseException ex) { System.err.println("Error Processing Command Options:"); formatter.printHelp("tuio-mouse-driver", options); return; } //load conversion services ServiceLoader<ProtoConverter> services = ServiceLoader.load(ProtoConverter.class); //create zeromq context ZMQ.Context context = ZMQ.context(1); // Connect our subscriber socket ZMQ.Socket subscriber = context.socket(ZMQ.SUB); subscriber.setIdentity(ZeroMqMouse.class.getName().getBytes()); //this could change I guess so we can get different data subscrptions. subscriber.subscribe("TuioCursor".getBytes()); // subscriber.subscribe("TuioTime".getBytes()); subscriber.connect("tcp://" + zeromq_port); System.out.println("Subscribed to " + zeromq_port + " for ZeroMQ messages."); // Get updates, expect random Ctrl-C death String msg = ""; MouseDriver md = new MouseDriver(); while (!msg.equalsIgnoreCase("END")) { boolean success = false; byte[] recv = subscriber.recv(); com.google.protobuf.GeneratedMessage message = null; TuioPoint pt = null; String type = recv.length > 0 ? new String(recv) : ""; recv = subscriber.recv(); switch (type) { case "TuioCursor.PROTOBUF": try { //it is a cursor? message = com.artistech.protobuf.TuioProtos.Cursor.parseFrom(recv); success = true; } catch (Exception ex) { } break; case "TuioTime.PROTOBUF": // try { // //it is a cursor? // message = com.artistech.protobuf.TuioProtos.Time.parseFrom(recv); // success = true; // } catch (Exception ex) { // } break; case "TuioObject.PROTOBUF": try { //it is a cursor? message = com.artistech.protobuf.TuioProtos.Object.parseFrom(recv); success = true; } catch (Exception ex) { } break; case "TuioBlob.PROTOBUF": try { //it is a cursor? message = com.artistech.protobuf.TuioProtos.Blob.parseFrom(recv); success = true; } catch (Exception ex) { } break; case "TuioCursor.JSON": try { //it is a cursor? pt = mapper.readValue(recv, TUIO.TuioCursor.class); success = true; } catch (Exception ex) { } break; case "TuioTime.JSON": // try { // //it is a cursor? // pt = mapper.readValue(recv, TUIO.TuioTime.class); // success = true; // } catch (Exception ex) { // } break; case "TuioObject.JSON": try { //it is a cursor? pt = mapper.readValue(recv, TUIO.TuioObject.class); success = true; } catch (Exception ex) { } break; case "TuioBlob.JSON": try { //it is a cursor? pt = mapper.readValue(recv, TUIO.TuioBlob.class); success = true; } catch (Exception ex) { } break; case "TuioTime.OBJECT": break; case "TuioCursor.OBJECT": case "TuioObject.OBJECT": case "TuioBlob.OBJECT": try { //Try reading the data as a serialized Java object: try (ByteArrayInputStream bis = new ByteArrayInputStream(recv)) { //Try reading the data as a serialized Java object: ObjectInput in = new ObjectInputStream(bis); Object o = in.readObject(); //if it is of type Point (Cursor, Object, Blob), process: if (TuioPoint.class.isAssignableFrom(o.getClass())) { pt = (TuioPoint) o; process(pt, md); } success = true; } } catch (java.io.IOException | ClassNotFoundException ex) { } finally { } break; default: success = false; break; } if (message != null && success) { //ok, so we have a message that is not null, so it was protobuf: Object o = null; //look for a converter that will suppor this objec type and convert: for (ProtoConverter converter : services) { if (converter.supportsConversion(message)) { o = converter.convertFromProtobuf(message); break; } } //if the type is of type Point (Cursor, Blob, Object), process: if (o != null && TuioPoint.class.isAssignableFrom(o.getClass())) { pt = (TuioPoint) o; } } if (pt != null) { process(pt, md); } } }
From source file:com.opensearchserver.affinities.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("d", "datadir", true, "Data directory"); 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-affinities.jar", options); return;/*from www. jav a 2 s . c o m*/ } int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 9092; File dataDir = new File(System.getProperty("user.home"), "opensearchserver_affinities"); if (cmd.hasOption("d")) dataDir = new File(cmd.getOptionValue("d")); if (!dataDir.exists()) throw new IOException("The data directory does not exists: " + dataDir); if (!dataDir.isDirectory()) throw new IOException("The data directory path is not a directory: " + dataDir); AffinityList.load(dataDir); UndertowJaxrsServer server = new UndertowJaxrsServer() .start(Undertow.builder().addHttpListener(port, "0.0.0.0")); server.deploy(Main.class); }
From source file:net.jingx.main.Main.java
/** * @param args/*w ww. j a va 2 s .com*/ * @throws IOException */ public static void main(String[] args) { CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption(CLI_SECRET, true, "generate secret key (input is the configuration key from google)"); options.addOption(CLI_PASSCODE, true, "generate passcode (input is the secret key)"); options.addOption(new Option(CLI_HELP, "print this message")); try { CommandLine line = parser.parse(options, args); if (line.hasOption(CLI_SECRET)) { String confKey = line.getOptionValue(CLI_SECRET); String secret = generateSecret(confKey); System.out.println("Your secret to generate pins: " + secret); } else if (line.hasOption(CLI_PASSCODE)) { String secret = line.getOptionValue(CLI_PASSCODE); String pin = computePin(secret, null); System.out.println(pin); } else if (line.hasOption(CLI_HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("GAuthCli", options); } else { EventQueue.invokeLater(new Runnable() { public void run() { try { MainGui window = new MainGui(); window.doSetVisible(); } catch (Exception e) { e.printStackTrace(); } } }); return; } System.out.println("Press any key to exit"); System.in.read(); } catch (Exception e) { System.out.println("Unexpected exception:" + e.getMessage()); } System.exit(0); }
From source file:eu.annocultor.utils.XmlUtils.java
public static void main(String... args) throws Exception { // Handling command line parameters with Apache Commons CLI Options options = new Options(); options.addOption(OptionBuilder.withArgName(OPT_FN).hasArg().isRequired() .withDescription("XML file name to be pretty-printed").create(OPT_FN)); // now lets parse the input CommandLineParser parser = new BasicParser(); CommandLine cmd;/*w w w . j a v a 2 s .co m*/ try { cmd = parser.parse(options, Utils.getCommandLineFromANNOCULTOR_ARGS(args)); } catch (ParseException pe) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("pretty", options); return; } List<File> files = Utils.expandFileTemplateFrom(new File("."), cmd.getOptionValue(OPT_FN)); for (File file : files) { // XML pretty print System.out.println("Pretty-print for file " + file); if (file.exists()) prettyPrintXmlFileSAX(file.getCanonicalPath()); else throw new Exception("File not found: " + file.getCanonicalPath()); } }
From source file:com.redhat.akashche.keystoregen.Launcher.java
public static void main(String[] args) throws Exception { try {/*from w ww . j a v a2 s . c o m*/ CommandLine cline = new GnuParser().parse(OPTIONS, args); if (cline.hasOption(VERSION_OPTION)) { out.println(VERSION); } else if (cline.hasOption(HELP_OPTION)) { throw new ParseException("Printing help page:"); } else if (0 == cline.getArgs().length && cline.hasOption(CONFIG_OPTION) && cline.hasOption(OUTPUT_OPTION)) { KeystoreConfig conf = parseConf(cline.getOptionValue(CONFIG_OPTION)); KeyStore ks = new KeystoreGenerator().generate(conf); writeKeystore(conf, ks, cline.getOptionValue(OUTPUT_OPTION)); } else { throw new ParseException("Incorrect arguments received!"); } } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); out.println(e.getMessage()); out.println(VERSION); formatter.printHelp("java -jar keystoregen.jar -c config.json -o output.p12", OPTIONS); } }
From source file:cc.wikitools.lucene.FetchWikipediaArticle.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(/*from ww w . j ava2 s . c o m*/ OptionBuilder.withArgName("path").hasArg().withDescription("index location").create(INDEX_OPTION)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("article id").create(ID_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("article title").create(TITLE_OPTION)); CommandLine cmdline = null; 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(ID_OPTION) || cmdline.hasOption(TITLE_OPTION)) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(FetchWikipediaArticle.class.getName(), options); System.exit(-1); } File indexLocation = new File(cmdline.getOptionValue(INDEX_OPTION)); if (!indexLocation.exists()) { System.err.println("Error: " + indexLocation + " does not exist!"); System.exit(-1); } WikipediaSearcher searcher = new WikipediaSearcher(indexLocation); PrintStream out = new PrintStream(System.out, true, "UTF-8"); if (cmdline.hasOption(ID_OPTION)) { int id = Integer.parseInt(cmdline.getOptionValue(ID_OPTION)); Document doc = searcher.getArticle(id); if (doc == null) { System.err.print("id " + id + " doesn't exist!\n"); } else { out.println(doc.getField(IndexField.TEXT.name).stringValue()); } } else { String title = cmdline.getOptionValue(TITLE_OPTION); Document doc = searcher.getArticle(title); if (doc == null) { System.err.print("article \"" + title + "\" doesn't exist!\n"); } else { out.println(doc.getField(IndexField.TEXT.name).stringValue()); } } searcher.close(); out.close(); }