List of usage examples for org.apache.commons.cli ParseException getLocalizedMessage
public String getLocalizedMessage()
From source file:org.voltdb.bulkloader.CLIDriver.java
/** * CLIDriver factory that parses command line arguments and allows * additional options to be included. See documentation for parse(). * * @param helpOptions command line help data * @param args command line arguments (and options) * @param addlCLISpecs additional CLISpec objects * @return CLIDriver object//from ww w. j ava 2 s . com */ public static CLIDriver parse(HelpData helpOptions, String[] args, CLISpec... addlCLISpecs) { CLIDriver config = new CLIDriver(helpOptions); try { config.parseArgs(args, addlCLISpecs); } catch (ParseException e) { config.abort(true, e.getLocalizedMessage()); // exits above } return config; }
From source file:org.wso2.test.ruwan.osgi.StartScan.java
private void dosScan(String[] args) { carbonHome = System.getenv("CARBON_HOME"); boolean matchPackageVersions = false; CommandLineParser parser = new BasicParser(); try {/*from ww w . j av a 2s . c o m*/ CommandLine cmd = parser.parse(getOptions(), args); if (cmd.hasOption("d")) { carbonHome = cmd.getOptionValue(CMD_OPTION_CARBON_HOME); } matchPackageVersions = cmd.hasOption(CMD_OPTION_PACKAGE_VERSIONS); } catch (ParseException e) { System.out.println(e.getLocalizedMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("scan", getOptions()); return; } if (carbonHome == null) { System.out.println( "Either CARBON_HOME environment variable needs to be set or needs to be provided as a command line argument"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("scan", getOptions()); return; } File root = new File(carbonHome); BundleScanner bundleScanner = new BundleScanner(matchPackageVersions); if (root.isDirectory() && root.isDirectory()) { bundleScanner.scanDirectory(root); Map<String, List<Bundle>> duplicates = bundleScanner.getDuplicateExports(); printMap(duplicates); } else { System.out.println("The given location does not point to a valid directory " + carbonHome); } }
From source file:sonumina.boqa.BOQABenchmark.java
/** * Parses the command line and returns a corresponding * BOQA object. /*from w w w . j a va 2 s. c o m*/ * * @param args */ public static BOQA parseCommandLine(String[] args) { Options opt = new Options(); opt.addOption("o", "ontology", true, "Path or URL to the ontology file."); opt.addOption("a", "annotations", true, "Path or URL to files containing annotations."); opt.addOption("c", "considerFreqOnly", false, "If specified, only items with frequencies are considered."); opt.addOption("m", "maxTerms", true, "Defines the maximal number of terms a random query can have. Default is " + MAX_TERMS); opt.addOption("s", "samplesPerItem", true, "Define the number of samples per item. Defaults to " + SAMPLES_PER_ITEM + "."); opt.addOption("r", "resultBaseName", true, "Defines the base name of the result files that are created during the benchmark. Defaults to \"" + RESULT_BASE_NAME + "\"."); opt.addOption(null, "alpha", true, "Specifies alpha (false-positive rate) during simulation. Default is " + ALPHA + "."); opt.addOption(null, "beta", true, "Specifies beta (false-negative rate) during simulation. Default is " + BETA + "."); opt.addOption(null, "sizeOfScoreDistribution", true, "Specifies the size of the score distribution. Default is " + SIZE_OF_SCORE_DISTRIBUTION + "."); opt.addOption("h", "help", false, "Shows this help"); BOQA boqa = new BOQA(); try { GnuParser parser = new GnuParser(); CommandLine cl; cl = parser.parse(opt, args); if (cl.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp(BOQABenchmark.class.getName(), opt); System.exit(0); } if (cl.hasOption('m')) MAX_TERMS = Integer.parseInt(cl.getOptionValue('m')); if (cl.hasOption('c')) CONSIDER_FREQUENCIES_ONLY = true; if (cl.hasOption('s')) SAMPLES_PER_ITEM = Integer.parseInt(cl.getOptionValue('s')); SIZE_OF_SCORE_DISTRIBUTION = Integer.parseInt(cl.getOptionValue("sizeOfScoreDistribution", "250000")); RESULT_BASE_NAME = cl.getOptionValue('r', RESULT_BASE_NAME); if (cl.hasOption("alpha")) ALPHA = Double.parseDouble(cl.getOptionValue("alpha")); if (cl.hasOption("beta")) BETA = Double.parseDouble(cl.getOptionValue("beta")); ontologyPath = cl.getOptionValue('o', ontologyPath); annotationPath = cl.getOptionValue('a', annotationPath); boqa.setSimulationAlpha(ALPHA); boqa.setSimulationBeta(BETA); boqa.setConsiderFrequenciesOnly(CONSIDER_FREQUENCIES_ONLY); boqa.setSimulationMaxTerms(MAX_TERMS); if (MAX_TERMS != -1) boqa.setMaxQuerySizeForCachedDistribution(MAX_TERMS); boqa.setSizeOfScoreDistribution(SIZE_OF_SCORE_DISTRIBUTION); } catch (ParseException e) { System.err.println("Faield to parse commandline: " + e.getLocalizedMessage()); System.exit(1); } return boqa; }
From source file:speedith.Main.java
/** * The main entry point to Speedith. <p>Parses the arguments and starts * Speedith either in interactive or batch mode.</p> * * @param args the Command line arguments to Speedith. *//*from w ww . ja va 2 s . c om*/ public static void main(String[] args) { CliOptions clargs = new CliOptions(); try { clargs.parse(args); // Did the user specify any of the 'print help' options? If so, just // print the info and exit. // Otherwise startup Speedith. if (clargs.isHelp()) { clargs.printHelp(); } else if (clargs.isListOutputFormats()) { printKnownFormats(); } else if (clargs.isListInferenceRules()) { printKnownInferenceRules(); } else if (clargs.isBatchMode()) { // ---- Starting up Speedith // Did the user provide a spider diagram to Speedith? String formula = clargs.getSpiderDiagram(); SpiderDiagram readSpiderDiagram = (formula == null) ? null : SpiderDiagramsReader.readSpiderDiagram(formula); // Did the user specify an output format? String outputFormat = clargs.getOutputFormat(); // Now print out the formula in the specified format if (readSpiderDiagram != null) { // Get the inference rule (and all of its possible arguments): String ir = clargs.getInferenceRule(); if (ir == null || ir.isEmpty()) { throw new IllegalArgumentException(i18n("APP_NO_INFERENCE_RULE")); } String spider = clargs.getSpider(); int subDiagramIndex = clargs.getSubDiagramIndex(); Region region = clargs.getRegion(); InferenceRule<? extends RuleArg> inferenceRule = InferenceRules.getInferenceRule(ir); if (inferenceRule == null) { throw new IllegalArgumentException(i18n("APP_UNKNOWN_INFERENCE_RULE")); } RuleArg ruleArg; if (subDiagramIndex >= 0) { if (!Strings.isNullOrEmpty(spider)) { if (region != null) { ruleArg = new SpiderRegionArg(0, subDiagramIndex, spider, region); } else { ruleArg = new SpiderArg(0, subDiagramIndex, spider); } } else { ruleArg = new SubDiagramIndexArg(0, subDiagramIndex); } } else { throw new IllegalArgumentException(i18n("MAIN_SUBDIAGRAM_INDEX_NEGATIVE")); } RuleApplicationResult subGoals = inferenceRule.apply(ruleArg, new Goals(Arrays.asList(readSpiderDiagram))); if (subGoals != null && subGoals.getGoals() != null && subGoals.getGoals().getGoalsCount() > 0) { readSpiderDiagram = subGoals.getGoals().getGoalAt(0); SDExporter exporter = SDExporting.getExporter(outputFormat, clargs.getOutputFormatArguments()); if (exporter == null) { throw new IllegalArgumentException(i18n("APP_UNKNOWN_EXPORTER")); } else { exporter.exportTo(readSpiderDiagram, System.out); } } System.out.println(); } } else { // We are not running in the batch mode. Ignore all arguments // and show the main form. SpeedithMainForm.main(args); } } catch (ParseException ex) { // Report why the parsing of the command line arguments failed and // print the help message (both to the error output). log(Level.SEVERE, i18n("ERR_CLI_PARSE_FAILED", ex.getLocalizedMessage()), ex); System.err.println(i18n("ERR_CLI_PARSE_FAILED", ex.getLocalizedMessage())); clargs.printHelp(System.err); System.exit(1); } catch (ReadingException rex) { // The spider diagram formula could not be read successfully. log(Level.SEVERE, i18n("ERR_READING_FORMULA", rex.getLocalizedMessage()), rex); System.out.println(i18n("ERR_READING_FORMULA", rex.getLocalizedMessage())); System.exit(1); } catch (Exception ex) { log(Level.SEVERE, ex.getLocalizedMessage(), ex); System.out.println(ex.toString()); System.exit(1); } }
From source file:uk.ac.ed.bio.SynthSys.SBMLDataTools.SBMLAddTimeCourseData.java
/** * Main command line call./*from ww w. j a v a 2s. c o m*/ * * @param args command line arguments * * @throws IOException if an unexpected IO error occurs. Most common errors are reported nicer * than throwing an exception. */ public static void main(String[] args) throws IOException { Options options = getCommandLineOptions(); try { CommandLineParser parser = new DefaultParser(); CommandLine commandLine = parser.parse(options, args); // Handle help option if (commandLine.hasOption(OPTION_HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(PROGRAM_NAME, options); return; } // Everything should be in the options so if there are any any left then we have an // error if (commandLine.getArgs().length != 0) { String error = "Usage error: unexpected arguments:"; for (String s : commandLine.getArgList()) { error = error + " " + s; } throw new ParseException(error); } // One of sbmlOut or csvOut is required if (!commandLine.hasOption(OPTION_SBML_OUT) && !commandLine.hasOption(OPTION_CSV_OUT)) { throw new ParseException("One of sbmlOut or csvOut arguments is required."); } // Get the CSV in file Reader csvInReader; if (commandLine.hasOption(OPTION_CSV_IN)) { String fileName = commandLine.getOptionValue(OPTION_CSV_IN); csvInReader = new BufferedReader(new FileReader(fileName)); } else { // Read from stdin csvInReader = new BufferedReader(new InputStreamReader(System.in)); } // Get SBML in reader SBMLDocument doc; if (commandLine.hasOption(OPTION_SBML_IN)) { File file = new File(commandLine.getOptionValue(OPTION_SBML_IN)); doc = SBMLReader.read(file); } else { // Create an empty SBML model int level = getIntegerOption(commandLine, OPTION_SBML_LEVEL, DEFAULT_SBML_LEVEL); int version = getIntegerOption(commandLine, OPTION_SBML_VERSION, DEFAULT_SBML_VERSION); doc = new SBMLDocument(level, version); doc.createModel("model"); } // Get SBML out file File sbmlOutFile = null; if (commandLine.hasOption(OPTION_SBML_OUT)) { sbmlOutFile = new File(commandLine.getOptionValue(OPTION_SBML_OUT)); } // CSV file out BufferedWriter csvOutWriter = null; if (commandLine.hasOption(OPTION_CSV_OUT)) { File csvFileOut = new File(commandLine.getOptionValue(OPTION_CSV_OUT)); csvOutWriter = new BufferedWriter(new FileWriter(csvFileOut)); } // Interpolator String interpolatorName = DEFAULT_INTERPOLATOR; Interpolator interpolator = null; if (commandLine.hasOption(OPTION_INTERPOLATOR)) { interpolatorName = commandLine.getOptionValue(OPTION_INTERPOLATOR); } // Map interpolator to appropriate class instance if (interpolatorName.equalsIgnoreCase("cubic")) { interpolator = new PolynomialInterpolator(new SplineInterpolator()); } else if (interpolatorName.equalsIgnoreCase("linear")) { interpolator = new PolynomialInterpolator(new LinearInterpolator()); } else { throw new ParseException("Unknown interpolator: " + interpolatorName); } // Do the work process(csvInReader, doc.getModel(), csvOutWriter, getSeparator(commandLine), interpolator); csvInReader.close(); if (csvOutWriter != null) csvOutWriter.close(); // Write the SBML file out if (commandLine.hasOption(OPTION_SBML_OUT)) { SBMLWriter.write(doc, sbmlOutFile, "SBMLAddTimeCourseData", "1.0"); } } catch (ParseException e) { System.err.println("Error: " + e.getLocalizedMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(PROGRAM_NAME, options); } catch (FileNotFoundException e) { System.err.println("Error: File not found: " + e.getLocalizedMessage()); } catch (WstxUnexpectedCharException e) { System.err.println("Error reading SBML file: " + e.getLocalizedMessage()); } catch (XMLStreamException e) { System.err.println("Error reading SBML file: " + e.getLocalizedMessage()); } catch (IllegalArgumentException e) { System.err.println("Error: " + e.getLocalizedMessage()); } }
From source file:visolate.Main.java
public static void main(final String[] argv) { CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("x", "flip-x", false, "flip around x axis"); options.addOption("y", "flip-y", false, "flip around y axis"); options.addOption("a", "absolute", false, "use absolute cooridnates"); options.addOption("d", "dpi", true, "dpi to use for rastering"); options.addOption("A", "auto", false, "auto-mode (run, save and exit)"); options.addOption("o", "outfile", true, "name of output file"); options.addOption("h", "help", false, "display this help and exit"); options.addOption("V", "version", false, "output version information and exit"); CommandLine commandline;/*ww w . j a va 2s . c o m*/ try { commandline = parser.parse(options, argv); } catch (ParseException e) { System.err.println(e.getLocalizedMessage()); System.exit(1); return; // make it clear to the compiler that the following code is not run } if (commandline.hasOption("version")) { System.out.println(APPNAME); return; } if (commandline.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("visolate [options] [filename]", options); return; } if (commandline.getArgs().length >= 2) { System.err.println("Error: Too many arguments."); System.exit(1); } try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //TODO: Make look and feel options } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedLookAndFeelException e) { // TODO Auto-generated catch block e.printStackTrace(); } final JFrame frame = new JFrame(APPNAME); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(DEF_LOC_X, DEF_LOC_Y); // Add the Enter key to the forward traversal keys, so fields loose focus // when using it in a field and we don't need to set up both, an ActionListener // and a FocusListener for each text/number field. Set<AWTKeyStroke> forwardKeys = new HashSet<AWTKeyStroke>( frame.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); Set<AWTKeyStroke> newForwardKeys = new HashSet<AWTKeyStroke>(forwardKeys); newForwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)); frame.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newForwardKeys); final Visolate visolate = new Visolate(); visolate.commandline = commandline; Container contentPane = frame.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(visolate, "Center"); contentPane.setBackground(Color.WHITE); SwingUtilities.invokeLater(new Runnable() { public void run() { frame.pack(); frame.setVisible(true); if (visolate.commandline.getArgs().length == 1) { visolate.loadFile(new File(visolate.commandline.getArgs()[0])); } else { visolate.loadDemo(); } if (visolate.commandline.hasOption("auto")) { System.out.println("Automatic processing enabled! Files will be overwritten without asking!"); visolate.auto_mode = true; } if (visolate.commandline.hasOption("dpi")) { visolate.getDisplay().setDPI(Integer.parseInt(visolate.commandline.getOptionValue("dpi"))); } if (visolate.commandline.hasOption("flip-x")) { visolate.model.setFlipX(true); } if (visolate.commandline.hasOption("flip-y")) { visolate.model.setFlipY(true); } if (visolate.commandline.hasOption("absolute")) { visolate.setAbsoluteCoordinates(true); } if (visolate.commandline.hasOption("outfile")) { visolate.setGcodeFile(visolate.commandline.getOptionValue("outfile")); } if (visolate.commandline.hasOption("auto")) { System.out.println("now starting fixing topology due to automatic mode"); visolate.processstatus = 1; visolate.fixTopology(); // fix.Topology() calls visolate.processFinished after its done. Also, the Toolpathprocessor does so. processstatus discriminates this. } visolate.model.rebuild(); } }); }