List of usage examples for org.apache.commons.cli HelpFormatter HelpFormatter
HelpFormatter
From source file:com.svds.tailer2kafka.main.Main.java
/** * Given command-line arguments, create GenericConsumerGroup * //from w w w. j av a 2 s. com * @param args command-line arguments to parse * @throws IOException */ public static void main(String[] args) throws IOException, InterruptedException { Options options = new Options(); options.addOption(OptionBuilder.isRequired().withLongOpt(TOPICNAME).withDescription("Kafka topic name") .hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(METADATABROKERLIST) .withDescription("Kafka metadata.broker.list").hasArg().create()); options.addOption( OptionBuilder.isRequired().withLongOpt(FILENAME).withDescription("Log filename").hasArg().create()); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { LOG.error(e.getMessage(), e); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("com.svds.tailer2kafka.main.Main", options); throw new IOException("Missing Args"); } Main main = new Main(); main.doWork(cmd); }
From source file:cc.twittertools.util.VerifySubcollection.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)); options.addOption(/* w w w . j ava2 s.c o m*/ OptionBuilder.withArgName("file").hasArg().withDescription("list of tweetids").create(ID_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(COLLECTION_OPTION) || !cmdline.hasOption(ID_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ExtractSubcollection.class.getName(), options); System.exit(-1); } String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION); LongOpenHashSet tweetids = new LongOpenHashSet(); File tweetidsFile = new File(cmdline.getOptionValue(ID_OPTION)); if (!tweetidsFile.exists()) { System.err.println("Error: " + tweetidsFile + " does not exist!"); System.exit(-1); } LOG.info("Reading tweetids from " + tweetidsFile); FileInputStream fin = new FileInputStream(tweetidsFile); BufferedReader br = new BufferedReader(new InputStreamReader(fin)); String s; while ((s = br.readLine()) != null) { tweetids.add(Long.parseLong(s)); } br.close(); fin.close(); LOG.info("Read " + tweetids.size() + " tweetids."); File file = new File(collectionPath); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } LongOpenHashSet seen = new LongOpenHashSet(); TreeMap<Long, String> tweets = Maps.newTreeMap(); PrintStream out = new PrintStream(System.out, true, "UTF-8"); StatusStream stream = new JsonStatusCorpusReader(file); Status status; int cnt = 0; while ((status = stream.next()) != null) { if (!tweetids.contains(status.getId())) { LOG.error("tweetid " + status.getId() + " doesn't belong in collection"); continue; } if (seen.contains(status.getId())) { LOG.error("tweetid " + status.getId() + " already seen!"); continue; } tweets.put(status.getId(), status.getJsonObject().toString()); seen.add(status.getId()); cnt++; } LOG.info("total of " + cnt + " tweets in subcollection."); for (Map.Entry<Long, String> entry : tweets.entrySet()) { out.println(entry.getValue()); } stream.close(); out.close(); }
From source file:com.picdrop.security.SecureStoreMain.java
static public void main(String[] args) throws ParseException, IOException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, KeyStoreException, KeyStoreException, InterruptedException { CommandLineParser cliP = new DefaultParser(); Options ops = generateBasicOptions(); CommandLine cli = cliP.parse(ops, args); HelpFormatter hlp = new HelpFormatter(); SecureStore ss;//from www. j av a 2 s .c o m String path = "."; try { if (cli.hasOption("help")) { hlp.printHelp("SecureStore", ops); System.exit(0); } if (cli.hasOption("keystore")) { path = cli.getOptionValue("keystore", "."); } if (cli.hasOption("create")) { ss = new SecureStore(path, false); ss.createKeyStore(); System.exit(0); } else { ss = new SecureStore(path, true); } if (cli.hasOption("list")) { Enumeration<String> en = ss.listAlias(); while (en.hasMoreElements()) { System.out.println(en.nextElement()); } System.exit(0); } if (cli.hasOption("store")) { ss.storeValue(cli.getOptionValues("store")[0], cli.getOptionValues("store")[1]); ss.writeStore(); System.exit(0); } if (cli.hasOption("clear")) { ss.deleteValue(cli.getOptionValue("clear")); ss.writeStore(); System.exit(0); } } finally { hlp.printHelp("SecureStore", ops); System.exit(0); } }
From source file:ca.ualberta.exemplar.core.Exemplar.java
public static void main(String[] rawArgs) throws FileNotFoundException, UnsupportedEncodingException { CommandLineParser cli = new BasicParser(); Options options = new Options(); options.addOption("h", "help", false, "shows this message"); options.addOption("b", "benchmark", true, "expects input to be a benchmark file (type = binary | nary)"); options.addOption("p", "parser", true, "defines which parser to use (parser = stanford | malt)"); CommandLine line = null;/*from w w w . j a va 2s .c o m*/ try { line = cli.parse(options, rawArgs); } catch (ParseException exp) { System.err.println(exp.getMessage()); System.exit(1); } String[] args = line.getArgs(); String parserName = line.getOptionValue("parser", "malt"); if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("sh ./exemplar", options); System.exit(0); } if (args.length != 2) { System.out.println("error: exemplar requires an input file and output file."); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("sh ./exemplar <input> <output>", options); System.exit(0); } File input = new File(args[0]); File output = new File(args[1]); String benchmarkType = line.getOptionValue("benchmark", ""); if (!benchmarkType.isEmpty()) { if (benchmarkType.equals("binary")) { BenchmarkBinary evaluation = new BenchmarkBinary(input, output, parserName); evaluation.runAndTime(); System.exit(0); } else { if (benchmarkType.equals("nary")) { BenchmarkNary evaluation = new BenchmarkNary(input, output, parserName); evaluation.runAndTime(); System.exit(0); } else { System.out.println("error: benchmark option has to be either 'binary' or 'nary'."); System.exit(0); } } } Parser parser = null; if (parserName.equals("stanford")) { parser = new ParserStanford(); } else { if (parserName.equals("malt")) { parser = new ParserMalt(); } else { System.out.println(parserName + " is not a valid parser."); System.exit(0); } } System.out.println("Starting EXEMPLAR..."); RelationExtraction exemplar = null; try { exemplar = new RelationExtraction(parser); } catch (FileNotFoundException e) { e.printStackTrace(); } BlockingQueue<String> inputQueue = new ArrayBlockingQueue<String>(QUEUE_SIZE); PlainTextReader reader = null; reader = new PlainTextReader(inputQueue, input); Thread readerThread = new Thread(reader); readerThread.start(); PrintStream statementsOut = null; try { statementsOut = new PrintStream(output, "UTF-8"); } catch (FileNotFoundException e1) { e1.printStackTrace(); System.exit(0); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); System.exit(0); } statementsOut.println("Subjects\tRelation\tObjects\tNormalized Relation\tSentence"); while (true) { String doc = null; try { doc = inputQueue.take(); } catch (InterruptedException e) { e.printStackTrace(); } if (doc.isEmpty()) { break; } List<RelationInstance> instances = exemplar.extractRelations(doc); for (RelationInstance instance : instances) { // Output SUBJ arguments in a separate field, for clarity boolean first = true; for (Argument arg : instance.getArguments()) { if (arg.argumentType.equals("SUBJ")) { if (first) { first = false; } else { statementsOut.print(",,"); } statementsOut.print(arg.argumentType + ":" + arg.entityId); } } // Output the original relation statementsOut.print("\t" + instance.getOriginalRelation() + "\t"); // Output the DOBJ arguments, followed by POBJ first = true; for (Argument arg : instance.getArguments()) { if (arg.argumentType.equals("DOBJ")) { if (first) { first = false; } else { statementsOut.print(",,"); } statementsOut.print(arg.argumentType + ":" + arg.entityId); } } for (Argument arg : instance.getArguments()) { if (arg.argumentType.startsWith("POBJ")) { if (first) { first = false; } else { statementsOut.print(",,"); } statementsOut.print(arg.argumentType + ":" + arg.entityId); } } statementsOut.print("\t" + instance.getNormalizedRelation()); statementsOut.print("\t" + instance.getSentence()); statementsOut.println(); } } System.out.println("Done!"); statementsOut.close(); }
From source file:com.github.zk1931.zabkv.Main.java
public static void main(String[] args) throws Exception { // Options for command arguments. Options options = new Options(); Option port = OptionBuilder.withArgName("port").hasArg(true).isRequired(true).withDescription("port number") .create("port"); Option ip = OptionBuilder.withArgName("ip").hasArg(true).isRequired(true) .withDescription("current ip address").create("ip"); Option join = OptionBuilder.withArgName("join").hasArg(true).withDescription("the addr of server to join.") .create("join"); Option help = OptionBuilder.withArgName("h").hasArg(false).withLongOpt("help") .withDescription("print out usages.").create("h"); options.addOption(port).addOption(ip).addOption(join).addOption(help); CommandLineParser parser = new BasicParser(); CommandLine cmd;/*from w ww. j ava 2 s .com*/ try { cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("zabkv", options); return; } } catch (ParseException exp) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("zabkv", options); return; } int zabPort = Integer.parseInt(cmd.getOptionValue("port")); String myIp = cmd.getOptionValue("ip"); if (zabPort < 5000 && zabPort >= 5010) { System.err.println("port parameter can have value only between 5000 & 5010"); System.exit(1); } int serverPort = zabPort % 5000 + 8000; Database db = new Database(myIp, zabPort, cmd.getOptionValue("join")); Server server = new Server(serverPort); ServletHandler handler = new ServletHandler(); server.setHandler(handler); ServletHolder holder = new ServletHolder(new RequestHandler(db)); handler.addServletWithMapping(holder, "/*"); server.start(); server.join(); System.out.println("hi"); }
From source file:com.github.jjYBdx4IL.utils.lang.ConstantClassCreator.java
public static void main(String[] args) { try {/*ww w. ja v a 2s . co m*/ CommandLineParser parser = new GnuParser(); Options options = new Options(); options.addOption(OPTNAME_H, OPTNAME_HELP, false, "show help (this page)"); options.addOption(null, OPTNAME_SYSPROP, true, "system property name(s)"); options.addOption(null, OPTNAME_OUTPUT_CLASSNAME, true, "output classname"); options.addOption(null, OPTNAME_OUTPUT_DIRECTORY, true, "output directory"); CommandLine line = parser.parse(options, args); if (line.hasOption(OPTNAME_H)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ConstantClassCreator.class.getName(), options); } else if (line.hasOption(OPTNAME_SYSPROP)) { new ConstantClassCreator().run(line); } } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:net.ovres.tuxcourser.TuxCourser.java
public static void main(String[] argss) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("WARN|INFO|FINE").hasArg() .withDescription("Set the log level. Valid values include WARN, INFO, and FINE.") .withLongOpt("loglevel").create("l")); options.addOption("h", "help", false, "Displays this help and exits"); options.addOption("v", "version", false, "Displays version information and exits"); options.addOption(OptionBuilder.withArgName("TYPE").hasArg() .withDescription("Sets the output type. Valid values are tux11 and ppracer05").withLongOpt("output") .create());/*from www . j a v a2 s .c o m*/ CommandLineParser parser = new GnuParser(); CommandLine line = null; try { line = parser.parse(options, argss); } catch (ParseException exp) { System.err.println(exp.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar TuxCourser.jar [Options]", "Options", options, ""); System.exit(-1); } if (line.hasOption("loglevel")) { String lvl = line.getOptionValue("loglevel"); Level logLevel = Level.parse(lvl); Logger.getLogger("net.ovres.tuxcourser").setLevel(logLevel); } if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar TuxCourser.jar [Options]", "Options", options, ""); return; } if (line.hasOption("version")) { System.out.println("TuxCourser Version " + Settings.getVersion()); return; } String[] remaining = line.getArgs(); // Initialize all the different item and terrain types ModuleClassLoader.load(); if (remaining.length == 0) { // Just show the gui. //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); new net.ovres.tuxcourser.gui.TuxCourserGui().setVisible(true); } else if (remaining.length == 3) { new TuxCourser().convertCourse(new File(remaining[0]), new File(remaining[1]), remaining[2], TYPE_TUXRACER11); } else { usage(); System.exit(-1); } }
From source file:it.tizianofagni.sparkboost.MPBoostLearnerExe.java
public static void main(String[] args) { Options options = new Options(); options.addOption("b", "binaryProblem", false, "Indicate if the input dataset contains a binary problem and not a multilabel one"); options.addOption("z", "labels0based", false, "Indicate if the labels IDs in the dataset to classifyLibSvmWithResults are already assigned in the range [0, numLabels-1] included"); options.addOption("l", "enableSparkLogging", false, "Enable logging messages of Spark"); options.addOption("w", "windowsLocalModeFix", true, "Set the directory containing the winutils.exe command"); options.addOption("dp", "documentPartitions", true, "The number of document partitions"); options.addOption("fp", "featurePartitions", true, "The number of feature partitions"); options.addOption("lp", "labelPartitions", true, "The number of label partitions"); CommandLineParser parser = new BasicParser(); CommandLine cmd = null;//from w w w . j av a 2 s. c o m String[] remainingArgs = null; try { cmd = parser.parse(options, args); remainingArgs = cmd.getArgs(); if (remainingArgs.length != 3) throw new ParseException("You need to specify all mandatory parameters"); } catch (ParseException e) { System.out.println("Parsing failed. Reason: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( MPBoostLearnerExe.class.getSimpleName() + " [OPTIONS] <inputFile> <outputFile> <numIterations>", options); System.exit(-1); } boolean binaryProblem = false; if (cmd.hasOption("b")) binaryProblem = true; boolean labels0Based = false; if (cmd.hasOption("z")) labels0Based = true; boolean enablingSparkLogging = false; if (cmd.hasOption("l")) enablingSparkLogging = true; if (cmd.hasOption("w")) { System.setProperty("hadoop.home.dir", cmd.getOptionValue("w")); } String inputFile = remainingArgs[0]; String outputFile = remainingArgs[1]; int numIterations = Integer.parseInt(remainingArgs[2]); long startTime = System.currentTimeMillis(); // Disable Spark logging. if (!enablingSparkLogging) { Logger.getLogger("org").setLevel(Level.OFF); Logger.getLogger("akka").setLevel(Level.OFF); } // Create and configure Spark context. SparkConf conf = new SparkConf().setAppName("Spark MPBoost learner"); JavaSparkContext sc = new JavaSparkContext(conf); // Create and configure learner. MpBoostLearner learner = new MpBoostLearner(sc); learner.setNumIterations(numIterations); if (cmd.hasOption("dp")) { learner.setNumDocumentsPartitions(Integer.parseInt(cmd.getOptionValue("dp"))); } if (cmd.hasOption("fp")) { learner.setNumFeaturesPartitions(Integer.parseInt(cmd.getOptionValue("fp"))); } if (cmd.hasOption("lp")) { learner.setNumLabelsPartitions(Integer.parseInt(cmd.getOptionValue("lp"))); } // Build classifier with MPBoost learner. BoostClassifier classifier = learner.buildModel(inputFile, labels0Based, binaryProblem); // Save classifier to disk. DataUtils.saveModel(sc, classifier, outputFile); long endTime = System.currentTimeMillis(); System.out.println("Execution time: " + (endTime - startTime) + " milliseconds."); }
From source file:it.tizianofagni.sparkboost.AdaBoostMHLearnerExe.java
public static void main(String[] args) { Options options = new Options(); options.addOption("b", "binaryProblem", false, "Indicate if the input dataset contains a binary problem and not a multilabel one"); options.addOption("z", "labels0based", false, "Indicate if the labels IDs in the dataset to classifyLibSvmWithResults are already assigned in the range [0, numLabels-1] included"); options.addOption("l", "enableSparkLogging", false, "Enable logging messages of Spark"); options.addOption("w", "windowsLocalModeFix", true, "Set the directory containing the winutils.exe command"); options.addOption("dp", "documentPartitions", true, "The number of document partitions"); options.addOption("fp", "featurePartitions", true, "The number of feature partitions"); options.addOption("lp", "labelPartitions", true, "The number of label partitions"); CommandLineParser parser = new BasicParser(); CommandLine cmd = null;//www. ja v a 2s . c o m String[] remainingArgs = null; try { cmd = parser.parse(options, args); remainingArgs = cmd.getArgs(); if (remainingArgs.length != 5) throw new ParseException("You need to specify all mandatory parameters"); } catch (ParseException e) { System.out.println("Parsing failed. Reason: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(AdaBoostMHLearnerExe.class.getSimpleName() + " [OPTIONS] <inputFile> <outputFile> <numIterations> <sparkMaster> <parallelismDegree>", options); System.exit(-1); } boolean binaryProblem = false; if (cmd.hasOption("b")) binaryProblem = true; boolean labels0Based = false; if (cmd.hasOption("z")) labels0Based = true; boolean enablingSparkLogging = false; if (cmd.hasOption("l")) enablingSparkLogging = true; if (cmd.hasOption("w")) { System.setProperty("hadoop.home.dir", cmd.getOptionValue("w")); } String inputFile = remainingArgs[0]; String outputFile = remainingArgs[1]; int numIterations = Integer.parseInt(remainingArgs[2]); String sparkMaster = remainingArgs[3]; int parallelismDegree = Integer.parseInt(remainingArgs[4]); long startTime = System.currentTimeMillis(); // Disable Spark logging. if (!enablingSparkLogging) { Logger.getLogger("org").setLevel(Level.OFF); Logger.getLogger("akka").setLevel(Level.OFF); } // Create and configure Spark context. SparkConf conf = new SparkConf().setAppName("Spark AdaBoost.MH learner"); JavaSparkContext sc = new JavaSparkContext(conf); // Create and configure learner. AdaBoostMHLearner learner = new AdaBoostMHLearner(sc); learner.setNumIterations(numIterations); if (cmd.hasOption("dp")) { learner.setNumDocumentsPartitions(Integer.parseInt(cmd.getOptionValue("dp"))); } if (cmd.hasOption("fp")) { learner.setNumFeaturesPartitions(Integer.parseInt(cmd.getOptionValue("fp"))); } if (cmd.hasOption("lp")) { learner.setNumLabelsPartitions(Integer.parseInt(cmd.getOptionValue("lp"))); } // Build classifier with MPBoost learner. BoostClassifier classifier = learner.buildModel(inputFile, labels0Based, binaryProblem); // Save classifier to disk. DataUtils.saveModel(sc, classifier, outputFile); long endTime = System.currentTimeMillis(); System.out.println("Execution time: " + (endTime - startTime) + " milliseconds."); }
From source file:edu.usc.pgroup.floe.client.commands.Signal.java
/** * Entry point for Scale command./* ww w. ja va 2 s .c o m*/ * @param args command line arguments sent by the floe.py script. */ public static void main(final String[] args) { Options options = new Options(); Option appOption = OptionBuilder.withArgName("name").hasArg().isRequired() .withDescription("Application Name").create("app"); Option pelletNameOption = OptionBuilder.withArgName("name").hasArg().isRequired() .withDescription("Pellet Name").create("pellet"); Option signalOption = OptionBuilder.withArgName("data").hasArg().withType(new String()) .withDescription("signal data to send to the pellet").create("data"); options.addOption(appOption); options.addOption(pelletNameOption); options.addOption(signalOption); CommandLineParser parser = new BasicParser(); CommandLine line; try { line = parser.parse(options, args); } catch (ParseException e) { LOGGER.error("Invalid command: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("scale options", options); return; } String app = line.getOptionValue("app"); String pellet = line.getOptionValue("pellet"); String data = line.getOptionValue("data"); LOGGER.info("Application: {}", app); LOGGER.info("Pellet: {}", pellet); LOGGER.info("data: {}", data); byte[] datab = Utils.serialize(data); try { TSignal signal = new TSignal(); signal.set_destApp(app); signal.set_destPellet(pellet); signal.set_data(datab); FloeClient.getInstance().getClient().signal(signal); } catch (TException e) { LOGGER.error("Error while connecting to the coordinator: {}", e); } }