List of usage examples for org.apache.commons.cli ParseException getMessage
public String getMessage()
From source file:edu.umd.cloud9.example.bigram.AnalyzeBigramRelativeFrequencyJson.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); CommandLine cmdline = null;/*from w ww . jav a 2 s . c om*/ 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<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> pairs = SequenceFileUtils .readDirectory(new Path(inputPath)); List<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> list1 = Lists.newArrayList(); List<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> list2 = Lists.newArrayList(); for (PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> p : pairs) { BigramRelativeFrequencyJson.MyTuple bigram = p.getLeftElement(); if (bigram.getJsonObject().get("Left").getAsString().equals("light")) { list1.add(p); } if (bigram.getJsonObject().get("Left").getAsString().equals("contain")) { list2.add(p); } } Collections.sort(list1, new Comparator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>>() { public int compare(PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e1, PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Iterator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> iter1 = Iterators .limit(list1.iterator(), 10); while (iter1.hasNext()) { PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> p = iter1.next(); BigramRelativeFrequencyJson.MyTuple bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); } Collections.sort(list2, new Comparator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>>() { public int compare(PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e1, PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Iterator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> iter2 = Iterators .limit(list2.iterator(), 10); while (iter2.hasNext()) { PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> p = iter2.next(); BigramRelativeFrequencyJson.MyTuple bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); } }
From source file:com.flaptor.indextank.storage.IndexesLogServer.java
public static void main(String[] args) throws IOException, InterruptedException { // create the parser CommandLineParser parser = new PosixParser(); int readerPort, managerPort; try {/*from www. ja va 2 s . c o m*/ // parse the command line arguments CommandLine line = parser.parse(getOptions(), args); if (line.hasOption("help")) { printHelp(getOptions(), null); System.exit(1); return; } String val = null; val = line.getOptionValue("reader_port", null); if (null != val) { readerPort = Integer.valueOf(val); } else { printHelp(getOptions(), "Must specify a server port"); System.exit(1); return; } val = null; val = line.getOptionValue("manager_port", null); if (null != val) { managerPort = Integer.valueOf(val); } else { printHelp(getOptions(), "Must specify a server port"); System.exit(1); return; } } catch (ParseException exp) { printHelp(getOptions(), exp.getMessage()); System.exit(1); return; } new IndexesLogServer(readerPort, managerPort).start(); }
From source file:io.scigraph.owlapi.loader.BatchOwlLoader.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new DefaultParser(); CommandLine cmd = null;//from ww w . j av a2 s . c om try { cmd = parser.parse(getOptions(), args); } catch (ParseException e) { System.err.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(BatchOwlLoader.class.getSimpleName(), getOptions()); System.exit(-1); } OwlLoadConfigurationLoader owlLoadConfigurationLoader = new OwlLoadConfigurationLoader( new File(cmd.getOptionValue('c').trim())); OwlLoadConfiguration config = owlLoadConfigurationLoader.loadConfig(); load(config); // TODO: Is Guice causing this to hang? #44 System.exit(0); }
From source file:com.examples.cloud.speech.SyncRecognizeClient.java
public static void main(String[] args) throws Exception { String audioFile = ""; String host = "speech.googleapis.com"; Integer port = 443;// www . j av a 2 s. c om Integer sampling = 16000; CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("uri").withDescription("path to audio uri").hasArg() .withArgName("FILE_PATH").create()); options.addOption( OptionBuilder.withLongOpt("host").withDescription("endpoint for api, e.g. speech.googleapis.com") .hasArg().withArgName("ENDPOINT").create()); options.addOption(OptionBuilder.withLongOpt("port").withDescription("SSL port, usually 443").hasArg() .withArgName("PORT").create()); options.addOption(OptionBuilder.withLongOpt("sampling").withDescription("Sampling Rate, i.e. 16000") .hasArg().withArgName("RATE").create()); try { CommandLine line = parser.parse(options, args); if (line.hasOption("uri")) { audioFile = line.getOptionValue("uri"); } else { System.err.println("An Audio uri must be specified (e.g. file:///foo/baz.raw)."); System.exit(1); } if (line.hasOption("host")) { host = line.getOptionValue("host"); } else { System.err.println("An API enpoint must be specified (typically speech.googleapis.com)."); System.exit(1); } if (line.hasOption("port")) { port = Integer.parseInt(line.getOptionValue("port")); } else { System.err.println("An SSL port must be specified (typically 443)."); System.exit(1); } if (line.hasOption("sampling")) { sampling = Integer.parseInt(line.getOptionValue("sampling")); } else { System.err.println("An Audio sampling rate must be specified."); System.exit(1); } } catch (ParseException exp) { System.err.println("Unexpected exception:" + exp.getMessage()); System.exit(1); } ManagedChannel channel = AsyncRecognizeClient.createChannel(host, port); SyncRecognizeClient client = new SyncRecognizeClient(channel, URI.create(audioFile), sampling); try { client.recognize(); } finally { client.shutdown(); } }
From source file:com.google.flightmap.parsing.faa.nfd.tools.RecordStructGenerator.java
public static void main(String args[]) { CommandLine line = null;//from ww w . j ava 2 s.c o 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 defPath = line.getOptionValue(DEF_FILE_OPTION); final File def = new File(defPath); try { (new RecordStructGenerator(def)).execute(); } catch (IOException ioEx) { ioEx.printStackTrace(); System.exit(2); } }
From source file:com.gordcorp.jira2db.App.java
public static void main(String[] args) throws Exception { File log4jFile = new File("log4j.xml"); if (log4jFile.exists()) { DOMConfigurator.configure("log4j.xml"); }/* ww w .j av a2 s . co m*/ Option help = new Option("h", "help", false, "print this message"); @SuppressWarnings("static-access") Option project = OptionBuilder.withLongOpt("project").withDescription("Only sync Jira project PROJECT") .hasArg().withArgName("PROJECT").create(); @SuppressWarnings("static-access") Option property = OptionBuilder.withArgName("property=value").hasArgs(2).withValueSeparator() .withDescription("use value for given property").create("D"); @SuppressWarnings("static-access") Option testJira = OptionBuilder.withLongOpt("test-jira") .withDescription("Test the connection to Jira and print the results").create(); @SuppressWarnings("static-access") Option forever = OptionBuilder.withLongOpt("forever") .withDescription("Will continue polling Jira and syncing forever").create(); Options options = new Options(); options.addOption(help); options.addOption(project); options.addOption(property); options.addOption(testJira); options.addOption(forever); CommandLineParser parser = new GnuParser(); try { CommandLine line = parser.parse(options, args); if (line.hasOption(help.getOpt())) { printHelp(options); return; } // Overwrite the properties file with command line arguments if (line.hasOption("D")) { String[] values = line.getOptionValues("D"); for (int i = 0; i < values.length; i = i + 2) { String key = values[i]; // If user does not provide a value for this property, use // an empty string String value = ""; if (i + 1 < values.length) { value = values[i + 1]; } log.info("Setting key=" + key + " value=" + value); PropertiesWrapper.set(key, value); } } if (line.hasOption("test-jira")) { testJira(); } else { JiraSynchroniser jira = new JiraSynchroniser(); if (line.hasOption("project")) { jira.setProjects(Arrays.asList(new String[] { line.getOptionValue("project") })); } if (line.hasOption("forever")) { jira.syncForever(); } else { jira.syncAll(); } } } catch (ParseException exp) { log.error("Parsing failed: " + exp.getMessage()); } catch (Exception e) { log.error(e.getMessage(), e); } }
From source file:edu.ucsb.cs.eager.sa.cerebro.Cerebro.java
public static void main(String[] args) { Options options = new Options(); options.addOption("ccp", "cerebro-classpath", true, "Cerebro classpath"); options.addOption("c", "class", true, "Class to be used as the starting point"); options.addOption("dnc", "disable-nec-classes", false, "Disable loading of necessary classes"); options.addOption("wp", "whole-program", false, "Enable whole program mode"); CommandLine cmd;/*from w w w . j av a 2s. c o m*/ try { CommandLineParser parser = new BasicParser(); cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage() + "\n"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Cerebro", options); return; } String classPath = cmd.getOptionValue("ccp"); if (classPath == null) { System.err.println("Cerebro classpath (ccp) option is required"); return; } else { String[] paths = classPath.split(":"); for (String p : paths) { File file = new File(p); if (!file.exists()) { System.err.println("Path segment: " + p + " mentioned in classpath does not exist"); return; } } } String startingPoint = cmd.getOptionValue("c"); if (startingPoint == null) { System.err.println("Starting point class (c) option is required"); return; } Cerebro cerebro = new Cerebro(classPath, startingPoint); cerebro.setLoadNecessaryClasses(!cmd.hasOption("dnc")); cerebro.setWholeProgramMode(cmd.hasOption("wp")); cerebro.setVerbose(true); cerebro.analyze(); }
From source file:com.evolveum.midpoint.tools.gui.Main.java
public static void main(String[] args) throws Exception { Options options = new Options(); Option propertiesLocaleDelimiter = new Option("d", "delimiter", true, "Delimiter for locale name in properties file. Default is '_' (underscore)."); options.addOption(propertiesLocaleDelimiter); Option targetFolder = new Option("t", "targetFolder", true, "Target folder where properties file is generated."); targetFolder.setRequired(true);//from ww w.j a va 2 s . com options.addOption(targetFolder); Option baseFolder = new Option("b", "baseFolder", true, "Base folder used for properties files searching."); baseFolder.setRequired(true); options.addOption(baseFolder); Option localesToCheck = new Option("l", "locale", true, "Locales to check."); localesToCheck.setRequired(true); options.addOption(localesToCheck); Option recursiveFolderToCheck = new Option("r", "folderRecursive", true, "Folder used for recursive search for properties files."); options.addOption(recursiveFolderToCheck); Option nonRecursiveFolderToCheck = new Option("n", "folderNonRecursive", true, "Folder used for non recursive search for properties files."); options.addOption(nonRecursiveFolderToCheck); Option help = new Option("h", "help", false, "Print this help."); options.addOption(help); Option disableBackup = new Option("db", "disableBackup", false, "Disable backuping property files."); options.addOption(disableBackup); try { CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(options, args); if (line.hasOption(help.getOpt())) { printHelp(options); return; } if (!line.hasOption(recursiveFolderToCheck.getOpt()) && !line.hasOption(nonRecursiveFolderToCheck.getOpt())) { printHelp(options); return; } GeneratorConfiguration config = new GeneratorConfiguration(); if (line.hasOption(baseFolder.getOpt())) { config.setBaseFolder(new File(line.getOptionValue(baseFolder.getOpt()))); } if (line.hasOption(targetFolder.getOpt())) { config.setTargetFolder(new File(line.getOptionValue(targetFolder.getOpt()))); } if (line.hasOption(propertiesLocaleDelimiter.getOpt())) { config.setPropertiesLocaleDelimiter(line.getOptionValue(propertiesLocaleDelimiter.getOpt())); } if (line.hasOption(recursiveFolderToCheck.getOpt())) { String[] recursives = line.getOptionValues(recursiveFolderToCheck.getOpt()); if (recursives != null && recursives.length > 0) { for (String recursive : recursives) { config.getRecursiveFolderToCheck().add(recursive); } } } if (line.hasOption(nonRecursiveFolderToCheck.getOpt())) { String[] nonRecursives = line.getOptionValues(nonRecursiveFolderToCheck.getOpt()); if (nonRecursives != null && nonRecursives.length > 0) { for (String nonRecursive : nonRecursives) { config.getNonRecursiveFolderToCheck().add(nonRecursive); } } } if (line.hasOption(localesToCheck.getOpt())) { String[] locales = line.getOptionValues(localesToCheck.getOpt()); for (String locale : locales) { config.getLocalesToCheck().add(getLocaleFromString(locale)); } } if (line.hasOption(disableBackup.getOpt())) { config.setDisableBackup(true); } PropertiesGenerator generator = new PropertiesGenerator(config); generator.generate(); } catch (ParseException ex) { System.out.println("Error: " + ex.getMessage()); printHelp(options); } catch (Exception ex) { System.out.println("Something is broken."); ex.printStackTrace(); } }
From source file:com.github.braully.graph.UtilResult.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);/* ww w . j a va 2s .c o m*/ options.addOption(input); Option verb = new Option("v", "verbose", false, "verbose process"); input.setRequired(false); options.addOption(verb); Option output = new Option("o", "output", true, "output file"); output.setRequired(false); options.addOption(output); 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 inputFilePath = cmd.getOptionValue("input"); if (inputFilePath == null) { inputFilePath = "/home/strike/grafos-para-processar/mft2/resultado.txt"; } if (inputFilePath != null) { if (inputFilePath.toLowerCase().endsWith(".txt")) { processFileTxt(inputFilePath); } else if (inputFilePath.toLowerCase().endsWith(".json")) { processFileJson(inputFilePath); } } }
From source file:com.act.lcms.v2.TraceIndexAnalyzer.java
public static void main(String[] args) throws Exception { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());//from w ww. j a v a2s . com } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(TraceIndexExtractor.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(TraceIndexExtractor.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } File rocksDBFile = new File(cl.getOptionValue(OPTION_INDEX_PATH)); if (!rocksDBFile.exists()) { System.err.format("Index file at %s does not exist, nothing to analyze", rocksDBFile.getAbsolutePath()); HELP_FORMATTER.printHelp(TraceIndexExtractor.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } LOGGER.info("Starting analysis"); TraceIndexAnalyzer analyzer = new TraceIndexAnalyzer(); analyzer.runExtraction(rocksDBFile, new File(cl.getOptionValue(OPTION_OUTPUT_PATH))); LOGGER.info("Done"); }