List of usage examples for org.apache.commons.cli Parser parse
public CommandLine parse(Options options, String[] arguments, Properties properties, boolean stopAtNonOption) throws ParseException
From source file:com.rockagen.commons.util.CmdUtil.java
/** * Return a commandLine object by specifies {@link Parser},{@link Options}, * <code>arguments</code>,<code>stopAtNonOption</code> * /*from w ww.ja v a 2s. com*/ * @param parser * see abstract {@link Parser},and interface * {@link CommandLineParser} * @param options * the <code>Options</code> * @param arguments * the <code>arguments</code> * @param properties the <code>properties</code> * @param stopAtNonOption * specifies whether to stop interpreting the arguments when a * non option has been encountered and to add them to the * CommandLines args list. * @return the <code>CommandLine</code> * @throws ParseException * ParseException if an error occurs when parsing the arguments. */ public static CommandLine parse(Parser parser, Options options, String[] arguments, Properties properties, boolean stopAtNonOption) throws ParseException { CommandLine line = parser.parse(options, arguments, properties, stopAtNonOption); return line; }
From source file:com.conversantmedia.mapreduce.tool.ToolContext.java
/** * Parse the arguments./*w w w .ja va 2 s .c o m*/ * * @param args the command line arguments * @throws Exception if the process fails * @throws ParseException if the command line parsing fails */ protected void parseFromArgs(String[] args) throws Exception { Options options = initOptions(); // Notify our listener if there is one... if (this.contextListener != null) { this.contextListener.afterInitOptions(options); } try { args = handleHelp(args, options); Properties props = new Properties(); args = getConfigOverrides(props, args); // Now parse the rest of 'em Parser parser = new PosixParserRequiredProps(); CommandLine line = null; line = parser.parse(options, args, props, false); // Populate our context values from the parsed command line populateContext(line); // Notify our listener if there is one... if (this.contextListener != null) { this.contextListener.afterParseCommandLine(line); } } catch (ParseException e) { showHelpAndExit(options, 1, e.getMessage()); } }