List of usage examples for org.apache.commons.cli ParseException getMessage
public String getMessage()
From source file:de.zazaz.iot.bosch.indego.util.IndegoIftttAdapter.java
public static void main(String[] args) { System.setProperty("log4j.configurationFile", "log4j2-indegoIftttAdapter-normal.xml"); Options options = new Options(); StringBuilder commandList = new StringBuilder(); for (DeviceCommand cmd : DeviceCommand.values()) { if (commandList.length() > 0) { commandList.append(", "); }/* w w w . j a v a2s . co m*/ commandList.append(cmd.toString()); } options.addOption(Option // .builder("c") // .longOpt("config") // .desc("The configuration file to use") // .required() // .hasArg() // .build()); options.addOption(Option // .builder("d") // .longOpt("debug") // .desc("Logs more details") // .build()); options.addOption(Option // .builder("?") // .longOpt("help") // .desc("Prints this help") // .build()); CommandLineParser parser = new DefaultParser(); CommandLine cmds = null; try { cmds = parser.parse(options, args); } catch (ParseException ex) { System.err.println(ex.getMessage()); System.err.println(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(IndegoIftttAdapter.class.getName(), options); System.exit(1); return; } if (cmds.hasOption("?")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(CmdLineTool.class.getName(), options); return; } if (cmds.hasOption("d")) { System.setProperty("log4j.configurationFile", "log4j2-indegoIftttAdapter-debug.xml"); } String configFileName = cmds.getOptionValue('c'); File configFile = new File(configFileName); if (!configFile.exists()) { System.err.println(String.format("The specified config file (%s) does not exist", configFileName)); System.err.println(); System.exit(2); return; } Properties properties = new Properties(); try (InputStream in = new FileInputStream(configFile)) { properties.load(in); } catch (IOException ex) { System.err.println(ex.getMessage()); System.err.println(String.format("Was not able to load the properties file (%s)", configFileName)); System.err.println(); } IftttIndegoAdapterConfiguration config = new IftttIndegoAdapterConfiguration(); config.setIftttMakerKey(properties.getProperty("indego.ifttt.maker.key")); config.setIftttIgnoreServerCertificate( Integer.parseInt(properties.getProperty("indego.ifttt.maker.ignore-server-certificate")) != 0); config.setIftttReceiverPort(Integer.parseInt(properties.getProperty("indego.ifttt.maker.receiver-port"))); config.setIftttReceiverSecret(properties.getProperty("indego.ifttt.maker.receiver-secret")); config.setIftttOfflineEventName(properties.getProperty("indego.ifttt.maker.eventname-offline")); config.setIftttOnlineEventName(properties.getProperty("indego.ifttt.maker.eventname-online")); config.setIftttErrorEventName(properties.getProperty("indego.ifttt.maker.eventname-error")); config.setIftttErrorClearedEventName(properties.getProperty("indego.ifttt.maker.eventname-error-cleared")); config.setIftttStateChangeEventName(properties.getProperty("indego.ifttt.maker.eventname-state-change")); config.setIndegoBaseUrl(properties.getProperty("indego.ifttt.device.base-url")); config.setIndegoUsername(properties.getProperty("indego.ifttt.device.username")); config.setIndegoPassword(properties.getProperty("indego.ifttt.device.password")); config.setPollingIntervalMs(Integer.parseInt(properties.getProperty("indego.ifttt.polling-interval-ms"))); IftttIndegoAdapter adapter = new IftttIndegoAdapter(config); adapter.startup(); }
From source file:com.act.biointerpretation.l2expansion.L2RenderingDriver.java
public static void main(String[] args) throws Exception { // Build command line parser. Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());//from w ww . j a va 2 s. c om } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { LOGGER.error("Argument parsing failed: %s", e.getMessage()); HELP_FORMATTER.printHelp(L2RenderingDriver.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } // Print help. if (cl.hasOption(OPTION_HELP)) { HELP_FORMATTER.printHelp(L2RenderingDriver.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } // Set up input corpus file. File corpusFile = new File(cl.getOptionValue(OPTION_CORPUS_PATH)); if (!corpusFile.exists()) { LOGGER.error("Input corpus file does not exist"); return; } //Set up output directory. File outputDirectory = new File(cl.getOptionValue(OPTION_OUTPUT_DIRECTORY)); if (outputDirectory.exists() && !outputDirectory.isDirectory()) { LOGGER.error("Can't render corpus: supplied image directory is an existing non-directory file."); return; } outputDirectory.mkdir(); LOGGER.info("Reading in corpus from file."); L2PredictionCorpus predictionCorpus = L2PredictionCorpus.readPredictionsFromJsonFile(corpusFile); LOGGER.info("Finished reading in corpus with %d predictions", predictionCorpus.getCorpus().size()); // Set image format options String format = cl.getOptionValue(OPTION_IMAGE_FORMAT, DEFAULT_IMAGE_FORMAT); Integer width = Integer.parseInt(cl.getOptionValue(OPTION_IMAGE_WIDTH, DEFAULT_IMAGE_WIDTH)); Integer height = Integer.parseInt(cl.getOptionValue(OPTION_IMAGE_HEIGHT, DEFAULT_IMAGE_HEIGHT)); // Render the corpus. LOGGER.info("Drawing images for each prediction in corpus."); ReactionRenderer reactionRenderer = new ReactionRenderer(format, width, height); PredictionCorpusRenderer renderer = new PredictionCorpusRenderer(reactionRenderer); renderer.renderCorpus(predictionCorpus, outputDirectory); LOGGER.info("L2RenderingDriver complete!"); }
From source file:com.google.flightmap.parsing.faa.nasr.AirspaceParser.java
public static void main(String args[]) { CommandLine line = null;/* w ww .j a v a 2 s . co m*/ try { final CommandLineParser parser = new PosixParser(); line = parser.parse(OPTIONS, args); } catch (ParseException pEx) { System.err.println(pEx.getMessage()); printHelp(line); System.exit(1); } if (line.hasOption(HELP_OPTION)) { printHelp(line); System.exit(0); } final String[] shapefiles = line.getOptionValues(SHAPEFILES_OPTION); final String dbFile = line.getOptionValue(AVIATION_DB_OPTION); try { for (String shapefile : shapefiles) { (new AirspaceParser(shapefile, dbFile)).execute(); } } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } }
From source file:com.svds.genericconsumer.main.GenericConsumerGroup.java
/** * Given command-line arguments, create GenericConsumerGroup * //from www. j av a 2 s .co m * @param args command-line arguments to parse * @throws IOException */ public static void main(String[] args) throws IOException { LOG.info("HELLO from main"); Options options = new Options(); options.addOption(OptionBuilder.isRequired().withLongOpt(ZOOKEEPER).withDescription("Zookeeper servers") .hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(GROUPID).withDescription("Kafka group id").hasArg() .create()); options.addOption(OptionBuilder.isRequired().withLongOpt(TOPICNAME).withDescription("Kafka topic name") .hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(THREADS).withType(Number.class) .withDescription("Number of threads").hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(CONSUMERCLASS) .withDescription("Consumer Class from processing topic name").hasArg().create()); options.addOption(OptionBuilder.withLongOpt(PARAMETERS) .withDescription("Parameters needed for the consumer Class if needed").hasArgs() .withValueSeparator(',').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("GenericConsumerGroup.main", options); throw new IOException(e); } try { GenericConsumerGroup consumerGroupExample = new GenericConsumerGroup(); consumerGroupExample.doWork(cmd); } catch (ParseException ex) { LOG.error("Error parsing command-line args"); throw new IOException(ex); } }
From source file:cc.twittertools.search.api.SearchStatusesThrift.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(HELP_OPTION, "show help")); options.addOption(OptionBuilder.withArgName("string").hasArg().withDescription("host").create(HOST_OPTION)); options.addOption(OptionBuilder.withArgName("port").hasArg().withDescription("port").create(PORT_OPTION)); options.addOption(/*from www . jav a 2 s.co m*/ OptionBuilder.withArgName("string").hasArg().withDescription("query id").create(QID_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("query text").create(QUERY_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("runtag").create(RUNTAG_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("maxid").create(MAX_ID_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of results to return") .create(NUM_RESULTS_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("group id").create(GROUP_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("access token").create(TOKEN_OPTION)); options.addOption(new Option(VERBOSE_OPTION, "print out complete document")); 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(HELP_OPTION) || !cmdline.hasOption(HOST_OPTION) || !cmdline.hasOption(PORT_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(SearchStatusesThrift.class.getName(), options); System.exit(-1); } String qid = cmdline.hasOption(QID_OPTION) ? cmdline.getOptionValue(QID_OPTION) : DEFAULT_QID; String query = cmdline.hasOption(QUERY_OPTION) ? cmdline.getOptionValue(QUERY_OPTION) : DEFAULT_Q; String runtag = cmdline.hasOption(RUNTAG_OPTION) ? cmdline.getOptionValue(RUNTAG_OPTION) : DEFAULT_RUNTAG; long maxId = cmdline.hasOption(MAX_ID_OPTION) ? Long.parseLong(cmdline.getOptionValue(MAX_ID_OPTION)) : DEFAULT_MAX_ID; int numResults = cmdline.hasOption(NUM_RESULTS_OPTION) ? Integer.parseInt(cmdline.getOptionValue(NUM_RESULTS_OPTION)) : DEFAULT_NUM_RESULTS; boolean verbose = cmdline.hasOption(VERBOSE_OPTION); String group = cmdline.hasOption(GROUP_OPTION) ? cmdline.getOptionValue(GROUP_OPTION) : null; String token = cmdline.hasOption(TOKEN_OPTION) ? cmdline.getOptionValue(TOKEN_OPTION) : null; TrecSearchThriftClient client = new TrecSearchThriftClient(cmdline.getOptionValue(HOST_OPTION), Integer.parseInt(cmdline.getOptionValue(PORT_OPTION)), group, token); System.err.println("qid: " + qid); System.err.println("q: " + query); System.err.println("max_id: " + maxId); System.err.println("num_results: " + numResults); PrintStream out = new PrintStream(System.out, true, "UTF-8"); List<TResult> results = client.search(query, maxId, numResults); int i = 1; for (TResult result : results) { out.println(String.format("%s Q0 %d %d %f %s", qid, result.id, i, result.rsv, runtag)); if (verbose) { System.out.println("# " + result.toString().replaceAll("[\\n\\r]+", " ")); } i++; } out.close(); }
From source file:cc.twittertools.search.api.TrecSearchThriftServer.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(HELP_OPTION, "show help")); options.addOption(OptionBuilder.withArgName("port").hasArg().withDescription("port").create(PORT_OPTION)); options.addOption(/*from www . ja v a2 s . c o m*/ OptionBuilder.withArgName("index").hasArg().withDescription("index location").create(INDEX_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg() .withDescription("max number of threads in thread pool").create(MAX_THREADS_OPTION)); options.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("file containing access tokens").create(CREDENTIALS_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(HELP_OPTION) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(TrecSearchThriftServer.class.getName(), options); System.exit(-1); } int port = cmdline.hasOption(PORT_OPTION) ? Integer.parseInt(cmdline.getOptionValue(PORT_OPTION)) : DEFAULT_PORT; int maxThreads = cmdline.hasOption(MAX_THREADS_OPTION) ? Integer.parseInt(cmdline.getOptionValue(MAX_THREADS_OPTION)) : DEFAULT_MAX_THREADS; File index = new File(cmdline.getOptionValue(INDEX_OPTION)); Map<String, String> credentials = null; if (cmdline.hasOption(CREDENTIALS_OPTION)) { credentials = Maps.newHashMap(); File cfile = new File(cmdline.getOptionValue(CREDENTIALS_OPTION)); if (!cfile.exists()) { System.err.println("Error: " + cfile + " does not exist!"); System.exit(-1); } for (String s : Files.readLines(cfile, Charsets.UTF_8)) { try { String[] arr = s.split(":"); credentials.put(arr[0], arr[1]); } catch (Exception e) { // Catch any exceptions from parsing file contain access tokens System.err.println("Error reading access tokens from " + cfile + "!"); System.exit(-1); } } } if (!index.exists()) { System.err.println("Error: " + index + " does not exist!"); System.exit(-1); } TServerSocket serverSocket = new TServerSocket(port); TrecSearch.Processor<TrecSearch.Iface> searchProcessor = new TrecSearch.Processor<TrecSearch.Iface>( new TrecSearchHandler(index, credentials)); TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverSocket); serverArgs.maxWorkerThreads(maxThreads); TServer thriftServer = new TThreadPoolServer( serverArgs.processor(searchProcessor).protocolFactory(new TBinaryProtocol.Factory())); thriftServer.serve(); }
From source file:is.merkor.core.cli.Main.java
public static void main(String[] args) throws Exception { List<String> results = new ArrayList<String>(); PrintStream out = new PrintStream(System.out, true, "UTF-8"); CommandLineParser parser = new GnuParser(); try {//from w ww . java 2 s . c om MerkorCoreCommandLineOptions.createOptions(); results = processCommandLine(parser.parse(MerkorCoreCommandLineOptions.options, args)); out.print("\n"); for (String str : results) { if (!str.equals("no message")) out.println(str); } out.print("\n"); if (results.isEmpty()) { out.println("nothing found for parameters: "); for (int i = 0; i < args.length; i++) out.println("\t" + args[i]); out.println("for help type: -help or see README.markdown"); out.print("\n"); } } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); } }
From source file:com.linkedin.restli.datagenerator.csharp.CSharpRythmGenerator.java
public static void main(String[] args) throws IOException { CommandLine cl = null;/*from ww w . j a va2 s. c om*/ try { final CommandLineParser parser = new DefaultParser(); cl = parser.parse(_options, args); } catch (ParseException e) { LOG.error("Invalid arguments: " + e.getMessage()); reportInvalidArguments(); } final CSharpRythmGenerator generator = new CSharpRythmGenerator(cl); generator.setupRythmEngine(); generator.generate(); Rythm.shutdown(); }
From source file:info.bitoo.Daemon.java
public static void main(String[] args) throws IOException { CommandLineParser parser = new PosixParser(); CommandLine cmd = null;/* www . j av a2 s . c om*/ try { cmd = parser.parse(createCommandLineOptions(), args); } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); } Properties props = Main.readConfiguration(cmd); BufferedReader input = new BufferedReader(new FileReader(cmd.getOptionValue("p"))); Daemon daemon = new Daemon(props, input); daemon.deamonMain(); }
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 www . j a v a 2 s. c om*/ 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."); }