parser.parse(args); } catch (CmdLineParser.OptionException oe) { System.err.println(oe.getMessage());
parser.parse(args); } catch (CmdLineParser.OptionException oe) { System.err.println(oe.getMessage());
parser.parse(args); } catch (CmdLineParser.OptionException oe) { System.err.println(oe.getMessage());
/** * <p> * This method has to be called initially by the code using this instance in order to configure. * </p> * <p> * Every subclass has to call <code>super.parseArgs(cmdLineArgs)</code> and then retrieve the options needed from * the returned CmdLineParser! * </p> * * @param cmdLineArgs */ public void parseArgs(String[] cmdLineArgs) throws Exception { // The Exception is not caught: Testbucket is greedy for any type of // output (piped back to it). this.cmdLineParser.parse(cmdLineArgs); }
/** * Extract the options and non-option arguments from the given * list of command-line arguments. The default locale is used for * parsing options whose values might be locale-specific. */ public final void parse( String[] argv ) throws IllegalOptionValueException, UnknownOptionException { // It would be best if this method only threw OptionException, but for // backwards compatibility with old user code we throw the two // exceptions above instead. parse(argv, Locale.getDefault()); }
/** * Extract the options and non-option arguments from the given * list of command-line arguments. The default locale is used for * parsing options whose values might be locale-specific. */ public final void parse( String[] argv ) throws IllegalOptionValueException, UnknownOptionException { // It would be best if this method only threw OptionException, but for // backwards compatibility with old user code we throw the two // exceptions above instead. parse(argv, Locale.getDefault()); }
/** * Extract the options and non-option arguments from the given * list of command-line arguments. The default locale is used for * parsing options whose values might be locale-specific. */ public final void parse( String[] argv ) throws IllegalOptionValueException, UnknownOptionException { // It would be best if this method only threw OptionException, but for // backwards compatibility with old user code we throw the two // exceptions above instead. parse(argv, Locale.getDefault()); }
/** * Extract the options and non-option arguments from the given * list of command-line arguments. The default locale is used for * parsing options whose values might be locale-specific. */ public final void parse( String[] argv ) throws IllegalOptionValueException, UnknownOptionException { // It would be best if this method only threw OptionException, but for // backwards compatibility with old user code we throw the two // exceptions above instead. parse(argv, Locale.getDefault()); }
/** * Extract the options and non-option arguments from the given list of command-line arguments. The default locale is * used for parsing options whose values might be locale-specific. * * @param argv * the argv * @throws IllegalOptionValueException * the illegal option value exception * @throws UnknownOptionException * the unknown option exception */ public final void parse(String[] argv) throws IllegalOptionValueException, UnknownOptionException { // It would be best if this method only threw OptionException, but for // backwards compatibility with old user code we throw the two // exceptions above instead. parse(argv, Locale.getDefault()); }
myOptions.parse(args);
public static void main( String[] args ) { CmdLineParser parser = new CmdLineParser(); CmdLineParser.Option date = parser.addOption(new ShortDateOption('d', "date")); try { parser.parse(args); } catch ( CmdLineParser.OptionException e ) { System.err.println(e.getMessage()); printUsage(); System.exit(2); } // Extract the values entered for the various options -- if the // options were not specified, the corresponding values will be // null. Date dateValue = (Date)parser.getOptionValue(date); // For testing purposes, we just print out the option values System.out.println("date: " + dateValue); // Extract the trailing command-line arguments ('a_number') in the // usage string above. String[] otherArgs = parser.getRemainingArgs(); System.out.println("remaining args: "); for ( int i = 0; i < otherArgs.length; ++i ) { System.out.println(otherArgs[i]); } // In a real program, one would pass the option values and other // arguments to a function that does something more useful. System.exit(0); }
CmdLineParser cmdLineParser = new CmdLineParser(); Option charsetOption = cmdLineParser.addStringOption('c', "charset"); cmdLineParser.parse(args); String encoding = (String) cmdLineParser.getOptionValue(charsetOption); String[] remainingArgs = cmdLineParser.getRemainingArgs();
/** * Parses the command line arguments * * @param args command line arguments * * @return parsed command line arguments * * @throws Exception thrown if the underlying libraries could not be initialized */ private static CmdLineParser parseCommandArguments(String[] args) throws Exception { if (args.length < 2) { printHelp(System.out); System.out.flush(); System.exit(0); } CmdLineParser parser = CLIParserBuilder.buildParser(); try { parser.parse(args); } catch (CmdLineParser.OptionException e) { errorAndExit(e.getMessage(), e); } Boolean helpEnabled = (Boolean) parser.getOptionValue(CLIParserBuilder.HELP_ARG); if (helpEnabled != null) { printHelp(System.out); System.out.flush(); System.exit(0); } return parser; }
parser.parse(args);
parser.parse(args);
parser.parse(args);
parser.parse(args);