List of usage examples for org.apache.commons.cli2 OptionException getMessage
public String getMessage()
From source file:br.edu.ifpb.pos.Main.java
public static void main(String[] args) { try {//from ww w.j a va 2 s .c o m Parser parser = new Parser(); // Commands commands = new Commands(); Group options = commands.createOptions(); // parser.setGroup(options); CommandLine line = parser.parse(args); CommandExecute execute = new CommandExecute(line, options); execute.run(); } catch (OptionException ex) { System.out.println(ex.getMessage()); } catch (ResourceException ex) { System.out.println("ERROR: " + ex.getMessage()); } }
From source file:com.martinkampjensen.thesis.Main.java
private static CommandLine parse(String[] args, Group group) { final Parser parser = new Parser(); parser.setGroup(group);// w w w.ja va2 s . com CommandLine cmdLine = null; try { cmdLine = parser.parse(args); } catch (OptionException e) { System.out.println(e.getMessage()); exit(StatusCode.ARGUMENT); } return cmdLine; }
From source file:it.jnrpe.plugins.PluginProxy.java
/** * Executes the proxied plugin passing the received arguments as parameters. * /* w ww .j a v a 2 s .co m*/ * @param argsAry * The parameters to be passed to the plugin * @return The return value of the plugin. * @throws BadThresholdException * - */ public ReturnValue execute(final String[] argsAry) throws BadThresholdException { // CommandLineParser clp = new PosixParser(); try { HelpFormatter hf = new HelpFormatter(); // configure a parser Parser cliParser = new Parser(); cliParser.setGroup(mainOptionsGroup); cliParser.setHelpFormatter(hf); CommandLine cl = cliParser.parse(argsAry); // Inject the context... InjectionUtils.inject(proxiedPlugin, getContext()); Thread.currentThread().setContextClassLoader(proxiedPlugin.getClass().getClassLoader()); ReturnValue retValue = proxiedPlugin.execute(new PluginCommandLine(cl)); if (retValue == null) { String msg = "Plugin [" + getPluginName() + "] with args [" + StringUtils.join(argsAry) + "] returned null"; retValue = new ReturnValue(Status.UNKNOWN, msg); } return retValue; } catch (BadThresholdException bte) { throw bte; } catch (OptionException e) { String msg = e.getMessage(); LOG.error(getContext(), "Error parsing plugin '" + getPluginName() + "' command line : " + msg, e); return new ReturnValue(Status.UNKNOWN, msg); } }
From source file:com.gsinnovations.howdah.AbstractJob.java
/** Parse the arguments specified based on the options defined using the * various <code>addOption</code> methods. If -h is specified or an * exception is encountered print help and return null. Has the * side effect of setting inputPath and outputPath * if <code>addInputOption</code> or <code>addOutputOption</code> * or <code>mapred.input.dir</code> or <code>mapred.output.dir</code> * are present in the Configuration.// w ww.j av a2s. c o m * * @return a Map<String,Sting> containing options and their argument values. * The presence of a flag can be tested using <code>containsKey</code>, while * argument values can be retrieved using <code>get(optionName</code>. The * names used for keys are the option name parameter prefixed by '--'. * * */ public Map<String, String> parseArguments(String[] args) { Option helpOpt = addOption(DefaultOptionCreator.helpOption()); addOption("tempDir", null, "Intermediate output directory", "temp"); addOption("startPhase", null, "First phase to run", "0"); addOption("endPhase", null, "Last phase to run", String.valueOf(Integer.MAX_VALUE)); GroupBuilder gBuilder = new GroupBuilder().withName("Job-Specific Options:"); for (Option opt : options) { gBuilder = gBuilder.withOption(opt); } Group group = gBuilder.create(); CommandLine cmdLine; try { Parser parser = new Parser(); parser.setGroup(group); parser.setHelpOption(helpOpt); cmdLine = parser.parse(args); } catch (OptionException e) { log.error(e.getMessage()); CommandLineUtil.printHelpWithGenericOptions(group); return null; } if (cmdLine.hasOption(helpOpt)) { CommandLineUtil.printHelpWithGenericOptions(group); return null; } try { parseDirectories(cmdLine); } catch (IllegalArgumentException e) { log.error(e.getMessage()); CommandLineUtil.printHelpWithGenericOptions(group); return null; } argMap = new TreeMap<String, String>(); maybePut(argMap, cmdLine, this.options.toArray(new Option[this.options.size()])); log.info("Command line arguments: {}", argMap); return argMap; }
From source file:my.mahout.AbstractJob.java
/** * * @param args The args to parse/*from www .j a va 2 s. c o m*/ * @param inputOptional if false, then the input option, if set, need not be present. If true and input is an option * and there is no input, then throw an error * @param outputOptional if false, then the output option, if set, need not be present. If true and output is an * option and there is no output, then throw an error * @return the args parsed into a map. */ public Map<String, List<String>> parseArguments(String[] args, boolean inputOptional, boolean outputOptional) throws IOException { Option helpOpt = addOption(DefaultOptionCreator.helpOption()); addOption("tempDir", null, "Intermediate output directory", "temp"); addOption("startPhase", null, "First phase to run", "0"); addOption("endPhase", null, "Last phase to run", String.valueOf(Integer.MAX_VALUE)); GroupBuilder gBuilder = new GroupBuilder().withName("Job-Specific Options:"); for (Option opt : options) { gBuilder = gBuilder.withOption(opt); } group = gBuilder.create(); CommandLine cmdLine; try { Parser parser = new Parser(); parser.setGroup(group); parser.setHelpOption(helpOpt); cmdLine = parser.parse(args); } catch (OptionException e) { log.error(e.getMessage()); CommandLineUtil.printHelpWithGenericOptions(group, e); return null; } if (cmdLine.hasOption(helpOpt)) { CommandLineUtil.printHelpWithGenericOptions(group); return null; } try { parseDirectories(cmdLine, inputOptional, outputOptional); } catch (IllegalArgumentException e) { log.error(e.getMessage()); CommandLineUtil.printHelpWithGenericOptions(group); return null; } argMap = new TreeMap<String, List<String>>(); maybePut(argMap, cmdLine, this.options.toArray(new Option[this.options.size()])); this.tempPath = new Path(getOption("tempDir")); if (!hasOption("quiet")) { log.info("Command line arguments: {}", argMap); } return argMap; }
From source file:org.apache.mahout.classifier.bayes.mapreduce.common.JobExecutor.java
/** * Execute a bayes classification job. Input and output path are parsed from the input parameters. * //w w w . ja v a 2 s . c om * @param args * input parameters. * @param job * the job to execute. * @throws Exception * any exception thrown at job execution. * */ public static void execute(String[] args, BayesJob job) throws IOException { GroupBuilder gbuilder = new GroupBuilder(); Option inputOpt = DefaultOptionCreator.inputOption().create(); Option outputOpt = DefaultOptionCreator.outputOption().create(); Option helpOpt = DefaultOptionCreator.helpOption(); Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(outputOpt).withOption(helpOpt) .create(); try { Parser parser = new Parser(); parser.setGroup(group); CommandLine cmdLine = parser.parse(args); if (cmdLine.hasOption(helpOpt)) { CommandLineUtil.printHelp(group); return; } Path input = new Path(cmdLine.getValue(inputOpt).toString()); Path output = new Path(cmdLine.getValue(outputOpt).toString()); BayesParameters bayesParams = new BayesParameters(); bayesParams.setGramSize(1); job.runJob(input, output, bayesParams); } catch (OptionException e) { log.error(e.getMessage()); CommandLineUtil.printHelp(group); } }
From source file:org.apache.mahout.math.hadoop.decomposer.EigenVerificationJob.java
public static Map<String, String> handleArgs(String[] args) { Option eigenInputOpt = buildOption("eigenInput", "ei", "The Path for purported eigenVector input files (SequenceFile<WritableComparable,VectorWritable>.", null);//from w w w . j a v a 2 s . co m Option corpusInputOpt = buildOption("corpusInput", "ci", "The Path for corpus input files (SequenceFile<WritableComparable,VectorWritable>."); Option outOpt = DefaultOptionCreator.outputOption().create(); Option helpOpt = DefaultOptionCreator.helpOption(); Option inMemOpt = buildOption("inMemory", "mem", "Buffer eigen matrix into memory (if you have enough!)", "false"); Option errorOpt = buildOption("maxError", "err", "Maximum acceptable error", "0.05"); Option minEigenValOpt = buildOption("minEigenvalue", "mev", "Minimum eigenvalue to keep the vector for", "0.0"); GroupBuilder gBuilder = new GroupBuilder().withName("Options").withOption(eigenInputOpt) .withOption(corpusInputOpt).withOption(helpOpt).withOption(outOpt).withOption(inMemOpt) .withOption(errorOpt).withOption(minEigenValOpt); Group group = gBuilder.create(); Map<String, String> argMap = new HashMap<String, String>(); CommandLine cmdLine; try { Parser parser = new Parser(); parser.setGroup(group); cmdLine = parser.parse(args); } catch (OptionException e) { log.error(e.getMessage()); CommandLineUtil.printHelp(group); return null; } if (cmdLine.hasOption(helpOpt)) { CommandLineUtil.printHelp(group); return argMap; } maybePut(argMap, cmdLine, eigenInputOpt, corpusInputOpt, helpOpt, outOpt, inMemOpt, errorOpt, minEigenValOpt); return argMap; }
From source file:org.opencloudengine.flamingo.mapreduce.core.AbstractJob.java
/** * ? ??? ./*from w w w. j av a 2 s .c o m*/ * ? <tt>-h</tt> ? ??? <tt>null</tt>? . * * @param args ?? * @return ?? ??? ? ? {@code Map<String,String>}. * ??? key ? ? ? '--'? prefix . * ? ? {@code Map<String,String>} ? ? ? '--'? ??? . */ public Map<String, String> parseArguments(String[] args) throws Exception { Option helpOpt = addOption(DefaultOptionCreator.helpOption()); addOption("tempDir", null, " ", false); addOption("startPhase", null, " ", "0"); addOption("endPhase", null, " ", String.valueOf(Integer.MAX_VALUE)); GroupBuilder groupBuilder = new GroupBuilder().withName("Hadoop MapReduce Job :"); for (Option opt : options) { groupBuilder = groupBuilder.withOption(opt); } Group group = groupBuilder.create(); CommandLine cmdLine; try { Parser parser = new Parser(); parser.setGroup(group); parser.setHelpOption(helpOpt); cmdLine = parser.parse(args); } catch (OptionException e) { log.error(e.getMessage()); CommandLineUtil.printHelpWithGenericOptions(group, e); return null; } if (cmdLine.hasOption(helpOpt)) { CommandLineUtil.printHelpWithGenericOptions(group); return null; } try { parseDirectories(cmdLine); } catch (IllegalArgumentException e) { log.error(e.getMessage()); CommandLineUtil.printHelpWithGenericOptions(group); return null; } argMap = new TreeMap<String, String>(); maybePut(argMap, cmdLine, this.options.toArray(new Option[this.options.size()])); log.info("Command line arguments: ", argMap); Set<String> keySet = argMap.keySet(); for (Iterator<String> iterator = keySet.iterator(); iterator.hasNext();) { String key = iterator.next(); log.info(" {} = {}", key, argMap.get(key)); } return argMap; }