List of usage examples for org.apache.commons.cli ParseException getMessage
public String getMessage()
From source file:com.movielabs.availstool.AvailsTool.java
public static void main(String[] args) throws Exception { String fileName, outFile, sheetName; int sheetNum = -1; Logger log = LogManager.getLogger(AvailsTool.class.getName()); log.info("Initializing logger"); Options options = new Options(); options.addOption(Opts.v.name(), false, "verbose mode"); options.addOption(Opts.s.name(), true, "specify sheet"); options.addOption(Opts.f.name(), true, "specify file name"); options.addOption(Opts.o.name(), true, "specify output file name"); options.addOption(Opts.sstoxml.name(), false, "convert avails spreadsheet to XML"); options.addOption(Opts.xmltoss.name(), false, "convert avails XML to a spreadsheet"); options.addOption(Opts.dumpsheet.name(), false, "dump a single sheet from a spreadsheet"); options.addOption(Opts.dumpss.name(), false, "dump a spreadsheet file"); options.addOption(Opts.wx.name(), false, "treat warning as fatal error"); options.addOption(Opts.clean.name(), false, "clean up data entries"); CommandLineParser cli = new DefaultParser(); try {// w ww .j a v a 2s . com CommandLine cmd = cli.parse(options, args); boolean optToXML = cmd.hasOption(Opts.sstoxml.name()); boolean optToSS = cmd.hasOption(Opts.xmltoss.name()); boolean optDumpSS = cmd.hasOption(Opts.dumpss.name()); boolean optDumpSheet = cmd.hasOption(Opts.dumpsheet.name()); fileName = cmd.getOptionValue(Opts.f.name()); sheetName = cmd.getOptionValue(Opts.s.name()); boolean clean = cmd.hasOption(Opts.clean.name()); boolean wx = cmd.hasOption(Opts.wx.name()); boolean verbose = cmd.hasOption(Opts.v.name()); AvailSS ss; AvailsSheet as; String message; if (sheetName != null) { Pattern pat = Pattern.compile("^\\d+$"); Matcher m = pat.matcher(sheetName); if (m.matches()) sheetNum = Integer.parseInt(sheetName); } if (fileName == null) throw new ParseException("input file not specified"); if (!(optToXML | optToSS | optDumpSS | optDumpSheet)) throw new ParseException("missing operation"); if (optToXML) { if (optToSS | optDumpSS | optDumpSheet) throw new ParseException("more than one operation specified"); outFile = cmd.getOptionValue(Opts.o.name()); if (outFile == null) throw new ParseException("output file not specified"); ss = new AvailSS(fileName, log, wx, clean); if (sheetNum < 0) as = ss.addSheet(sheetName); else as = ss.addSheet(sheetNum); message = "toXML file: " + fileName + " sheet: " + sheetName; log.info(message); if (verbose) System.out.println(message); log.info("Options: -clean:" + clean + "; -wx:" + wx + "; output file: " + outFile); String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date()); String shortDesc = String.format("generated XML from %s:%s on %s", fileName, sheetName, timeStamp); as.makeXMLFile(outFile, shortDesc); } else if (optToSS) { if (optToXML | optDumpSS | optDumpSheet) throw new ParseException("more than one operation specified"); // TODO implement this outFile = cmd.getOptionValue(Opts.o.name()); if (outFile == null) throw new ParseException("output file not specified"); AvailXML x = new AvailXML(fileName, log); x.makeSS(outFile); } else if (optDumpSS) { if (optToXML | optToSS | optDumpSheet) throw new ParseException("more than one operation specified"); message = "dumping file: " + fileName; log.info(message); if (verbose) System.out.println(message); AvailSS.dumpFile(fileName); } else { // dumpSheet if (sheetName == null) throw new ParseException("sheet name not specified"); message = "dumping file: " + fileName + " sheet: " + sheetName; log.info(message); if (verbose) System.out.println(message); ss = new AvailSS(fileName, log, wx, clean); if (sheetNum < 0) as = ss.addSheet(sheetName); else as = ss.addSheet(sheetNum); ss.dumpSheet(sheetName); } } catch (ParseException exp) { System.out.println("bad command line: " + exp.getMessage()); usage(); System.exit(-1); } }
From source file:de.mfo.jsurf.Main.java
/** * @param args//w w w . j a v a 2 s . com */ public static void main(String[] args) { String jsurf_filename = ""; Options options = new Options(); options.addOption("s", "size", true, "width (and height) of a image (default: " + size + ")"); options.addOption("q", "quality", true, "quality of the rendering: 0 (low), 1 (medium, default), 2 (high), 3 (extreme)"); options.addOption("o", "output", true, "output PNG into this file (- means standard output. Use ./- to denote a file literally named -.)"); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); String cmd_line_syntax = "jsurf [options] jsurf_file"; String help_header = "jsurf is a renderer for algebraic surfaces. If - is specified as a filename the jsurf file is read from standard input. " + "Use ./- to denote a file literally named -."; String help_footer = ""; try { CommandLine cmd = parser.parse(options, args); if (cmd.getArgs().length > 0) jsurf_filename = cmd.getArgs()[0]; else { formatter.printHelp(cmd_line_syntax, help_header, options, help_footer); return; } if (cmd.hasOption("output")) { } if (cmd.hasOption("size")) size = Integer.parseInt(cmd.getOptionValue("size")); int quality = 1; if (cmd.hasOption("quality")) quality = Integer.parseInt(cmd.getOptionValue("quality")); switch (quality) { case 0: aam = AntiAliasingMode.ADAPTIVE_SUPERSAMPLING; aap = AntiAliasingPattern.OG_1x1; break; case 2: aam = AntiAliasingMode.ADAPTIVE_SUPERSAMPLING; aap = AntiAliasingPattern.OG_4x4; break; case 3: aam = AntiAliasingMode.SUPERSAMPLING; aap = AntiAliasingPattern.OG_4x4; break; case 1: aam = AntiAliasingMode.ADAPTIVE_SUPERSAMPLING; aap = AntiAliasingPattern.QUINCUNX; } } catch (ParseException exp) { System.out.println("Unexpected exception:" + exp.getMessage()); System.exit(-1); } catch (NumberFormatException nfe) { formatter.printHelp(cmd_line_syntax, help_header, options, help_footer); System.exit(-1); } final Properties jsurf = new Properties(); try { if (jsurf_filename.equals("-")) jsurf.load(System.in); else jsurf.load(new FileReader(jsurf_filename)); FileFormat.load(jsurf, asr); } catch (Exception e) { System.err.println("Unable to read jsurf file " + jsurf_filename); e.printStackTrace(); System.exit(-2); } asr.setAntiAliasingMode(aam); asr.setAntiAliasingPattern(aap); // display the image in a window final String window_title = "jsurf: " + jsurf_filename; SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame f = new JFrame(window_title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSurferRenderPanel p = null; try { p = new JSurferRenderPanel(jsurf); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } f.setContentPane(p); // f.getContentPane().add( new JLabel( new ImageIcon( window_image ) ) ); f.pack(); // f.setResizable( false ); f.setVisible(true); } }); }
From source file:cc.twittertools.search.api.TrecSearchThriftLoadGenerator.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(OptionBuilder.withArgName("index").hasArg().withDescription("host").create(HOST_OPTION)); options.addOption(/* w w w . jav a 2s . c o m*/ OptionBuilder.withArgName("num").hasArg().withDescription("threads").create(THREADS_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of queries to process") .create(LIMIT_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)); 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)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(TrecSearchThriftServer.class.getName(), options); System.exit(-1); } String host = cmdline.getOptionValue(HOST_OPTION); int port = cmdline.hasOption(PORT_OPTION) ? Integer.parseInt(cmdline.getOptionValue(PORT_OPTION)) : DEFAULT_PORT; int numThreads = cmdline.hasOption(THREADS_OPTION) ? Integer.parseInt(cmdline.getOptionValue(THREADS_OPTION)) : DEFAULT_THREADS; int limit = cmdline.hasOption(LIMIT_OPTION) ? Integer.parseInt(cmdline.getOptionValue(LIMIT_OPTION)) : Integer.MAX_VALUE; String group = cmdline.hasOption(GROUP_OPTION) ? cmdline.getOptionValue(GROUP_OPTION) : null; String token = cmdline.hasOption(TOKEN_OPTION) ? cmdline.getOptionValue(TOKEN_OPTION) : null; String queryFile = "data/queries.trec2005efficiency.txt"; new TrecSearchThriftLoadGenerator(new File(queryFile), limit).withThreads(numThreads) .withCredentials(group, token).run(host, port); }
From source file:co.turnus.analysis.buffers.BoundedBufferSchedulingCliLauncher.java
public static void main(String[] args) { try {//from w ww. j ava 2 s .c om CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(cliOptions, args); Configuration config = parseCommandLine(cmd); // init models AnalysisActivator.init(); // set logger verbosity if (config.getBoolean(VERBOSE, false)) { TurnusLogger.setLevel(TurnusLevel.ALL); } File tDir = new File(config.getString(TRACE_PROJECT)); TraceProject project = TraceProject.load(tDir); BoundedBufferScheduling bbs = new BoundedBufferScheduling(project); bbs.setConfiguration(config); BufferMinimizationData data = bbs.run(); TurnusLogger.info("Storing results..."); File outPath = new File(config.getString(OUTPUT_PATH)); // store the analysis report String uuid = UUID.randomUUID().toString(); File rFile = new File(outPath, uuid + "." + TurnusExtension.REPORT); Report report = DataFactory.eINSTANCE.createReport(); report.setDate(new Date()); report.setComment("Report with only Bounded Buffer Scheduling results analysis"); report.getDataSet().add(data); EcoreHelper.storeEObject(report, new ResourceSetImpl(), rFile); TurnusLogger.info("TURNUS report stored in " + rFile); // store formatted reports String xlsName = config.getString(XLS, ""); if (!xlsName.isEmpty()) { File xlsFile = new File(outPath, xlsName + ".xls"); new XlsBufferMinimizationDataWriter().write(data, xlsFile); TurnusLogger.info("XLS report stored in " + xlsFile); } String bxdfName = config.getString(BXDF, ""); if (!bxdfName.isEmpty()) { File bxdfFile = new File(outPath, bxdfName + ".bxdf"); new XmlBufferMinimizationDataWriter().write(data, bxdfFile); TurnusLogger.info("BXDF files (one for each configuration) " + "stored in " + outPath); } TurnusLogger.info("Analysis Done!"); } catch (ParseException e) { TurnusLogger.error(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(BoundedBufferSchedulingCliLauncher.class.getSimpleName(), cliOptions); } catch (Exception e) { TurnusLogger.error(e.getCause().toString()); } }
From source file:com.adobe.aem.demomachine.Json2Csv.java
public static void main(String[] args) throws IOException { String inputFile1 = null;/*from w w w. j av a2 s . c o m*/ String inputFile2 = null; String outputFile = null; HashMap<String, String> hmReportSuites = new HashMap<String, String>(); // Command line options for this tool Options options = new Options(); options.addOption("c", true, "Filename 1"); options.addOption("r", true, "Filename 2"); options.addOption("o", true, "Filename 3"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("c")) { inputFile1 = cmd.getOptionValue("c"); } if (cmd.hasOption("r")) { inputFile2 = cmd.getOptionValue("r"); } if (cmd.hasOption("o")) { outputFile = cmd.getOptionValue("o"); } if (inputFile1 == null || inputFile1 == null || outputFile == null) { System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } // List of customers and report suites for these customers String sInputFile1 = readFile(inputFile1, Charset.defaultCharset()); sInputFile1 = sInputFile1.replaceAll("ObjectId\\(\"([0-9a-z]*)\"\\)", "\"$1\""); // Processing the list of report suites for each customer try { JSONArray jCustomers = new JSONArray(sInputFile1.trim()); for (int i = 0, size = jCustomers.length(); i < size; i++) { JSONObject jCustomer = jCustomers.getJSONObject(i); Iterator<?> keys = jCustomer.keys(); String companyName = null; while (keys.hasNext()) { String key = (String) keys.next(); if (key.equals("company")) { companyName = jCustomer.getString(key); } } keys = jCustomer.keys(); while (keys.hasNext()) { String key = (String) keys.next(); if (key.equals("report_suites")) { JSONArray jReportSuites = jCustomer.getJSONArray(key); for (int j = 0, rSize = jReportSuites.length(); j < rSize; j++) { hmReportSuites.put(jReportSuites.getString(j), companyName); System.out.println(jReportSuites.get(j) + " for company " + companyName); } } } } // Creating the out put file PrintWriter writer = new PrintWriter(outputFile, "UTF-8"); writer.println("\"" + "Customer" + "\",\"" + "ReportSuite ID" + "\",\"" + "Number of Documents" + "\",\"" + "Last Updated" + "\""); // Processing the list of SOLR collections String sInputFile2 = readFile(inputFile2, Charset.defaultCharset()); sInputFile2 = sInputFile2.replaceAll("NumberLong\\(\"([0-9a-z]*)\"\\)", "\"$1\""); JSONObject jResults = new JSONObject(sInputFile2.trim()); JSONArray jCollections = jResults.getJSONArray("result"); for (int i = 0, size = jCollections.length(); i < size; i++) { JSONObject jCollection = jCollections.getJSONObject(i); String id = null; String number = null; String lastupdate = null; Iterator<?> keys = jCollection.keys(); while (keys.hasNext()) { String key = (String) keys.next(); if (key.equals("_id")) { id = jCollection.getString(key); } } keys = jCollection.keys(); while (keys.hasNext()) { String key = (String) keys.next(); if (key.equals("noOfDocs")) { number = jCollection.getString(key); } } keys = jCollection.keys(); while (keys.hasNext()) { String key = (String) keys.next(); if (key.equals("latestUpdateDate")) { lastupdate = jCollection.getString(key); } } Date d = new Date(Long.parseLong(lastupdate)); System.out.println(hmReportSuites.get(id) + "," + id + "," + number + "," + lastupdate + "," + new SimpleDateFormat("MM-dd-yyyy").format(d)); writer.println("\"" + hmReportSuites.get(id) + "\",\"" + id + "\",\"" + number + "\",\"" + new SimpleDateFormat("MM-dd-yyyy").format(d) + "\""); } writer.close(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.twentyn.patentSearch.DocumentIndexer.java
public static void main(String[] args) throws Exception { System.out.println("Starting up..."); System.out.flush();/* w w w .j a v a2 s . co m*/ Options opts = new Options(); opts.addOption(Option.builder("i").longOpt("input").hasArg().required() .desc("Input file or directory to index").build()); opts.addOption(Option.builder("x").longOpt("index").hasArg().required() .desc("Path to index file to generate").build()); opts.addOption(Option.builder("h").longOpt("help").desc("Print this help message and exit").build()); opts.addOption(Option.builder("v").longOpt("verbose").desc("Print verbose log output").build()); HelpFormatter helpFormatter = new HelpFormatter(); CommandLineParser cmdLineParser = new DefaultParser(); CommandLine cmdLine = null; try { cmdLine = cmdLineParser.parse(opts, args); } catch (ParseException e) { System.out.println("Caught exception when parsing command line: " + e.getMessage()); helpFormatter.printHelp("DocumentIndexer", opts); System.exit(1); } if (cmdLine.hasOption("help")) { helpFormatter.printHelp("DocumentIndexer", opts); System.exit(0); } if (cmdLine.hasOption("verbose")) { // With help from http://stackoverflow.com/questions/23434252/programmatically-change-log-level-in-log4j2 LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration ctxConfig = ctx.getConfiguration(); LoggerConfig logConfig = ctxConfig.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); logConfig.setLevel(Level.DEBUG); ctx.updateLoggers(); LOGGER.debug("Verbose logging enabled"); } LOGGER.info("Opening index at " + cmdLine.getOptionValue("index")); Directory indexDir = FSDirectory.open(new File(cmdLine.getOptionValue("index")).toPath()); /* The standard analyzer is too aggressive with chemical entities (it strips structural annotations, for one * thing), and the whitespace analyzer doesn't do any case normalization or stop word elimination. This custom * analyzer appears to treat chemical entities better than the standard analyzer without admitting too much * cruft to the index. */ Analyzer analyzer = CustomAnalyzer.builder().withTokenizer("whitespace").addTokenFilter("lowercase") .addTokenFilter("stop").build(); IndexWriterConfig writerConfig = new IndexWriterConfig(analyzer); writerConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); writerConfig.setRAMBufferSizeMB(1 << 10); IndexWriter indexWriter = new IndexWriter(indexDir, writerConfig); String inputFileOrDir = cmdLine.getOptionValue("input"); File splitFileOrDir = new File(inputFileOrDir); if (!(splitFileOrDir.exists())) { LOGGER.error("Unable to find directory at " + inputFileOrDir); System.exit(1); } DocumentIndexer indexer = new DocumentIndexer(indexWriter); PatentCorpusReader corpusReader = new PatentCorpusReader(indexer, splitFileOrDir); corpusReader.readPatentCorpus(); indexer.commitAndClose(); }
From source file:edu.wisc.doit.tcrypt.cli.TokenCrypt.java
public static void main(String[] args) throws IOException { // create Options object final Options options = new Options(); // operation opt group final OptionGroup cryptTypeGroup = new OptionGroup(); cryptTypeGroup.addOption(new Option("e", "encrypt", false, "Encrypt a token")); cryptTypeGroup.addOption(new Option("d", "decrypt", false, "Decrypt a token")); cryptTypeGroup// www .j a v a2 s .c om .addOption(new Option("c", "check", false, "Check if the string looks like an encrypted token")); cryptTypeGroup.setRequired(true); options.addOptionGroup(cryptTypeGroup); // token source opt group final OptionGroup tokenGroup = new OptionGroup(); final Option tokenOpt = new Option("t", "token", true, "The token(s) to operate on"); tokenOpt.setArgs(Option.UNLIMITED_VALUES); tokenGroup.addOption(tokenOpt); final Option tokenFileOpt = new Option("f", "file", true, "A file with one token per line to operate on, if - is specified stdin is used"); tokenGroup.addOption(tokenFileOpt); tokenGroup.setRequired(true); options.addOptionGroup(tokenGroup); final Option keyOpt = new Option("k", "keyFile", true, "Key file to use. Must be a private key for decryption and a public key for encryption"); keyOpt.setRequired(true); options.addOption(keyOpt); // create the parser final CommandLineParser parser = new GnuParser(); CommandLine line = null; try { // parse the command line arguments line = parser.parse(options, args); } catch (ParseException exp) { // automatically generate the help statement System.err.println(exp.getMessage()); final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java " + TokenCrypt.class.getName(), options, true); System.exit(1); } final Reader keyReader = createKeyReader(line); final TokenHandler tokenHandler = createTokenHandler(line, keyReader); if (line.hasOption("t")) { //tokens on cli final String[] tokens = line.getOptionValues("t"); for (final String token : tokens) { handleToken(tokenHandler, token); } } else { //tokens from a file final String tokenFile = line.getOptionValue("f"); final BufferedReader fileReader; if ("-".equals(tokenFile)) { fileReader = new BufferedReader(new InputStreamReader(System.in)); } else { fileReader = new BufferedReader(new FileReader(tokenFile)); } while (true) { final String token = fileReader.readLine(); if (token == null) { break; } handleToken(tokenHandler, token); } } }
From source file:com.examples.cloud.speech.StreamingRecognizeClient.java
public static void main(String[] args) throws Exception { String audioFile = ""; String host = "speech.googleapis.com"; Integer port = 443;/*w w w . ja v a 2 s . c om*/ Integer sampling = 16000; CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("file").withDescription("path to audio file").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("file")) { audioFile = line.getOptionValue("file"); } else { System.err.println("An Audio file must be specified (e.g. /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); StreamingRecognizeClient client = new StreamingRecognizeClient(channel, audioFile, sampling); try { client.recognize(); } finally { client.shutdown(); } }
From source file:com.mfalaize.zipdiff.Main.java
/** * The command line interface to zipdiff utility * * @param args The command line parameters *//*from w w w .j a va 2 s . c o m*/ public static void main(String[] args) { CommandLineParser parser = new DefaultParser(); try { CommandLine line = parser.parse(options, args); String filename1; String filename2; filename1 = line.getOptionValue(OPTION_FILE1); filename2 = line.getOptionValue(OPTION_FILE2); File f1 = new File(filename1); File f2 = new File(filename2); checkFile(f1); checkFile(f2); System.out.println("File 1 = " + f1); System.out.println("File 2 = " + f2); DifferenceCalculator calc = new DifferenceCalculator(f1, f2); String regularExpression; // todo - calc.setFilenamesToIgnore(); if (line.hasOption(OPTION_COMPARE_CRC_VALUES)) { calc.setCompareCRCValues(true); } else { calc.setCompareCRCValues(false); } if (line.hasOption(OPTION_IGNORE_CVS_FILES)) { calc.setIgnoreCVSFiles(true); } else { calc.setIgnoreCVSFiles(false); } if (line.hasOption(OPTION_COMPARE_TIMESTAMPS)) { calc.setIgnoreTimestamps(false); } else { calc.setIgnoreTimestamps(true); } if (line.hasOption(OPTION_REGEX)) { regularExpression = line.getOptionValue(OPTION_REGEX); Set<String> regexSet = new HashSet<String>(); regexSet.add(regularExpression); calc.setFilenameRegexToIgnore(regexSet); } boolean exitWithErrorOnDiff = false; if (line.hasOption(OPTION_EXIT_WITH_ERROR_ON_DIFF)) { exitWithErrorOnDiff = true; } Differences d = calc.getDifferences(); if (line.hasOption(OPTION_OUTPUT_FILE)) { String outputFilename = line.getOptionValue(OPTION_OUTPUT_FILE); writeOutputFile(outputFilename, d); } if (d.hasDifferences()) { if (line.hasOption(OPTION_VERBOSE)) { System.out.println(d); System.out.println(d.getFilename1() + " and " + d.getFilename2() + " are different."); } if (exitWithErrorOnDiff) { System.exit(EXITCODE_DIFF); } } else { System.out.println("No differences found."); } } catch (ParseException pex) { System.err.println(pex.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Main [options] ", options); System.exit(EXITCODE_ERROR); } catch (Exception ex) { ex.printStackTrace(); System.exit(EXITCODE_ERROR); } }
From source file:net.mmberg.nadia.processor.NadiaProcessor.java
/** * @param args//w w w . jav a 2 s . c o m */ @SuppressWarnings("static-access") public static void main(String[] args) { Class<? extends UserInterface> ui_class = ConsoleInterface.class; //default UI String dialog_file = default_dialog; //default dialogue //process command line args Options cli_options = new Options(); cli_options.addOption("h", "help", false, "print this message"); cli_options.addOption(OptionBuilder.withLongOpt("interface").withDescription("select user interface") .hasArg(true).withArgName("console, rest").create("i")); cli_options.addOption("f", "file", true, "specify dialogue path and file, e.g. -f /res/dialogue1.xml"); cli_options.addOption("r", "resource", true, "load dialogue (by name) from resources, e.g. -r dialogue1"); cli_options.addOption("s", "store", true, "load dialogue (by name) from internal store, e.g. -s dialogue1"); CommandLineParser parser = new org.apache.commons.cli.BasicParser(); try { CommandLine cmd = parser.parse(cli_options, args); //Help if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("nadia", cli_options, true); return; } //UI if (cmd.hasOption("i")) { String interf = cmd.getOptionValue("i"); if (interf.equals("console")) ui_class = ConsoleInterface.class; else if (interf.equals("rest")) ui_class = RESTInterface.class; } //load dialogue from path file if (cmd.hasOption("f")) { dialog_file = "file:///" + cmd.getOptionValue("f"); } //load dialogue from resources if (cmd.hasOption("r")) { dialog_file = config.getProperty(NadiaProcessorConfig.DIALOGUEDIR) + "/" + cmd.getOptionValue("r") + ".xml"; } //load dialogue from internal store if (cmd.hasOption("s")) { Dialog store_dialog = DialogStore.getInstance().getDialogFromStore((cmd.getOptionValue("s"))); store_dialog.save(); dialog_file = config.getProperty(NadiaProcessorConfig.DIALOGUEDIR) + "/" + cmd.getOptionValue("s") + ".xml"; } } catch (ParseException e1) { logger.severe("NADIA: loading by main-method failed. " + e1.getMessage()); e1.printStackTrace(); } //start Nadia with selected UI default_dialog = dialog_file; NadiaProcessor nadia = new NadiaProcessor(); try { ui = ui_class.newInstance(); ui.register(nadia); ui.start(); } catch (Exception e) { e.printStackTrace(); } }