From 169853692017480d065208cb768b83f1014cf68a Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Wed, 26 Feb 2020 07:34:48 +0100 Subject: added jargs, made it build again, but it bases on a really old Lucene 3.5.0, so it's no longer of any use for modern Lucene/SolR/ElasticSearch --- 3rdParty/jargs-1.0/LICENCE | 29 ++ 3rdParty/jargs-1.0/README | 60 +++ 3rdParty/jargs-1.0/TODO | 4 + 3rdParty/jargs-1.0/build.xml | 93 ++++ 3rdParty/jargs-1.0/doc/CHANGES | 66 +++ .../jargs-1.0/examples/gnu/AutoHelpParser.java | 87 ++++ .../jargs-1.0/examples/gnu/CustomOptionTest.java | 73 +++ .../examples/gnu/OptionParserSubclassTest.java | 71 +++ 3rdParty/jargs-1.0/examples/gnu/OptionTest.java | 139 ++++++ 3rdParty/jargs-1.0/pom.xml | 36 ++ .../src/main/java/jargs/gnu/CmdLineParser.java | 526 +++++++++++++++++++++ .../src/test/java/jargs/gnu/test/AllTests.java | 12 + .../java/jargs/gnu/test/CmdLineParserTestCase.java | 252 ++++++++++ .../java/jargs/gnu/test/CustomOptionTestCase.java | 71 +++ luceneanalyzer | 2 +- pom.xml | 6 +- 16 files changed, 1523 insertions(+), 4 deletions(-) create mode 100644 3rdParty/jargs-1.0/LICENCE create mode 100644 3rdParty/jargs-1.0/README create mode 100644 3rdParty/jargs-1.0/TODO create mode 100644 3rdParty/jargs-1.0/build.xml create mode 100644 3rdParty/jargs-1.0/doc/CHANGES create mode 100644 3rdParty/jargs-1.0/examples/gnu/AutoHelpParser.java create mode 100644 3rdParty/jargs-1.0/examples/gnu/CustomOptionTest.java create mode 100644 3rdParty/jargs-1.0/examples/gnu/OptionParserSubclassTest.java create mode 100644 3rdParty/jargs-1.0/examples/gnu/OptionTest.java create mode 100644 3rdParty/jargs-1.0/pom.xml create mode 100644 3rdParty/jargs-1.0/src/main/java/jargs/gnu/CmdLineParser.java create mode 100644 3rdParty/jargs-1.0/src/test/java/jargs/gnu/test/AllTests.java create mode 100644 3rdParty/jargs-1.0/src/test/java/jargs/gnu/test/CmdLineParserTestCase.java create mode 100644 3rdParty/jargs-1.0/src/test/java/jargs/gnu/test/CustomOptionTestCase.java diff --git a/3rdParty/jargs-1.0/LICENCE b/3rdParty/jargs-1.0/LICENCE new file mode 100644 index 0000000..509c1b7 --- /dev/null +++ b/3rdParty/jargs-1.0/LICENCE @@ -0,0 +1,29 @@ +Copyright (c) 2001-2003 Steve Purcell. +Copyright (c) 2002 Vidar Holen. +Copyright (c) 2002 Michal Ceresna. +Copyright (c) 2005 Ewan Mellor. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. Redistributions in +binary form must reproduce the above copyright notice, this list of +conditions and the following disclaimer in the documentation and/or other +materials provided with the distribution. Neither the name of the copyright +holder nor the names of its contributors may be used to endorse or promote +products derived from this software without specific prior written +permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/3rdParty/jargs-1.0/README b/3rdParty/jargs-1.0/README new file mode 100644 index 0000000..8ef5e96 --- /dev/null +++ b/3rdParty/jargs-1.0/README @@ -0,0 +1,60 @@ +JArgs command-line argument parsing library +=========================================== + +Copyright (c) 2001-2003 Steve Purcell. +Copyright (c) 2002 Vidar Holen. +Copyright (c) 2002 Michal Ceresna. +Copyright (c) 2005 Ewan Mellor. + +All rights reserved. + +Released under the terms of the BSD licence. See the file LICENCE for +details. + + +Prerequisites +------------- + +For each prerequisite, the version with which JArgs has been tested is given +in parentheses. Any version equal to or later than this should work. + +Apache Ant (1.4.1), by The Apache Software Foundation, from +http://ant.apache.org/. Ant is used to build JArgs, and to run its tests. + +JUnit (3.7), by Eric Gamma, et al, from http://sourceforge.net/projects/junit. +JUnit is used to run the unit tests, and is not needed to run the library +itself. + + +Installation +------------ + +To compile, package, and test the code, run + +ant + +Two jars are created, one called lib/jargs.jar, which contains the runtime +library, and one called lib/jargs-test.jar, which contains the unit tests and +the examples. The Javadoc APIs are created in doc/api. + +To use the library with your own code, simply ensure that lib/jargs.jar is on +the CLASSPATH. + + +Documentation +------------- + +The main documentation is the detailed worked example in +src/jargs/examples/gnu/OptionTest.java, plus the generated API documentation +in doc/api/. + + +Package contents +---------------- + + src/jargs/gnu -- The library itself. + src/jargs/examples/gnu -- Examples showing how to use the library. + src/jargs/test/gnu -- JUnit tests. + doc/ -- API and other documentation. + classes/ -- Compiled classes, once built. + lib/ -- JArgs jars, once built. diff --git a/3rdParty/jargs-1.0/TODO b/3rdParty/jargs-1.0/TODO new file mode 100644 index 0000000..90ccc3c --- /dev/null +++ b/3rdParty/jargs-1.0/TODO @@ -0,0 +1,4 @@ +JArgs to-do list +================ + +Nothing! (Fate, consider yourself tempted.) diff --git a/3rdParty/jargs-1.0/build.xml b/3rdParty/jargs-1.0/build.xml new file mode 100644 index 0000000..c6bc60e --- /dev/null +++ b/3rdParty/jargs-1.0/build.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/3rdParty/jargs-1.0/doc/CHANGES b/3rdParty/jargs-1.0/doc/CHANGES new file mode 100644 index 0000000..a05c4b4 --- /dev/null +++ b/3rdParty/jargs-1.0/doc/CHANGES @@ -0,0 +1,66 @@ +Changes from 0.5 to 1.0 +======================= + +- Added getOptionValue(Option, Object) which takes an Object as a potential + default value for the given Option. If the option is not present on the + command line, the default is returned instead. This addresses bug 1051346 + submitted by Tomas Znamenacek, and feature request 527808. + +- Added getOptionValues(Option) which will return a list of occurrences of a + single option, and added the ability internally to cope with such multiple + occurrences. This accepts and uses patch 1164413, and closes patch 1083615 + (it solves the same problem in a better way). + +- Added support for concatenated boolean options (those written -bcd where -b, + -c, and -d are boolean options). This accepts and uses patch 621087 by + Vidar Holen. + +- Added some more unit tests. + +- Some code clean-ups. + +Changes from 0.4 to 0.5 +======================= + +- Allow Options that have a long form only + +- Added LongOption + +- Corrected some typos in example code (thanks Chris McKay) + +- More tests + +Changes from 0.3 to 0.4 +======================= + +- Switched from makefiles to Ant + +- Some code clean-ups + +- Support locale-dependent parsing of Double options + +Changes from 0.2 to 0.3 +======================= + +- Added 'DoubleOption' class, and 'addDoubleOption()' convenience method + (suggested independently by Nick Roy and Karl Koster) + +- Made 'Option.getValue()' and 'Option.parseValue()' take a Locale, so + that parsing of values can be locale-dependent. (Locale-specific parsing + is not however implemented for DoubleOption and IntegerOption.) + +- Constructor of 'IllegalOptionValueException' is now public so that it can + be thrown by the 'parseValue()' methods of custom Option subclasses + +- 'CmdLineParser.addOption()' now returns the passed in Option, which + can make client code less clunky. + +- Added 'DoubleOption' to example classes + +- Added a 'CustomOptionTest' class to demonstrate subclassing of Option + via the implementation of a ShortDateOption class. + +- Added this CHANGES file. + +- Added overridden CmdLineParser.parse() which takes a Locale instance, + and made both versions of the method final. diff --git a/3rdParty/jargs-1.0/examples/gnu/AutoHelpParser.java b/3rdParty/jargs-1.0/examples/gnu/AutoHelpParser.java new file mode 100644 index 0000000..f42ec5f --- /dev/null +++ b/3rdParty/jargs-1.0/examples/gnu/AutoHelpParser.java @@ -0,0 +1,87 @@ +package jargs.examples.gnu; + +import jargs.gnu.CmdLineParser; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * This example shows how to dynamically create basic output for a --help option. + */ +public class AutoHelpParser extends CmdLineParser { + List optionHelpStrings = new ArrayList(); + + public Option addHelp(Option option, String helpString) { + optionHelpStrings.add(" -" + option.shortForm() + "/--" + option.longForm() + ": " + helpString); + return option; + } + + public void printUsage() { + System.err.println("usage: prog [options]"); + for (Iterator i = optionHelpStrings.iterator(); i.hasNext(); ) { + System.err.println(i.next()); + } + } + + public static void main( String[] args ) { + AutoHelpParser parser = new AutoHelpParser(); + CmdLineParser.Option verbose = parser.addHelp( + parser.addBooleanOption('v', "verbose"), + "Print extra information"); + CmdLineParser.Option size = parser.addHelp( + parser.addIntegerOption('s', "size"), + "The extent of the thing"); + CmdLineParser.Option name = parser.addHelp( + parser.addStringOption('n', "name"), + "Name given to the widget"); + CmdLineParser.Option fraction = parser.addHelp( + parser.addDoubleOption('f', "fraction"), + "What percentage should be discarded"); + CmdLineParser.Option help = parser.addHelp( + parser.addBooleanOption('h', "help"), + "Show this help message"); + + try { + parser.parse(args); + } + catch ( CmdLineParser.OptionException e ) { + System.err.println(e.getMessage()); + parser.printUsage(); + System.exit(2); + } + + if ( Boolean.TRUE.equals(parser.getOptionValue(help))) { + parser.printUsage(); + System.exit(0); + } + + // Extract the values entered for the various options -- if the + // options were not specified, the corresponding values will be + // null. + Boolean verboseValue = (Boolean)parser.getOptionValue(verbose); + Integer sizeValue = (Integer)parser.getOptionValue(size); + String nameValue = (String)parser.getOptionValue(name); + Double fractionValue = (Double)parser.getOptionValue(fraction); + + // For testing purposes, we just print out the option values + System.out.println("verbose: " + verboseValue); + System.out.println("size: " + sizeValue); + System.out.println("name: " + nameValue); + System.out.println("fraction: " + fractionValue); + + // Extract the trailing command-line arguments ('a_nother') 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); + } + +} diff --git a/3rdParty/jargs-1.0/examples/gnu/CustomOptionTest.java b/3rdParty/jargs-1.0/examples/gnu/CustomOptionTest.java new file mode 100644 index 0000000..2a1c45f --- /dev/null +++ b/3rdParty/jargs-1.0/examples/gnu/CustomOptionTest.java @@ -0,0 +1,73 @@ +package jargs.examples.gnu; + +import jargs.gnu.CmdLineParser; +import java.text.DateFormat; +import java.text.ParseException; +import java.util.Locale; +import java.util.Date; + +public class CustomOptionTest { + + private static void printUsage() { + System.err.println("usage: prog [{-d,--date} date]"); + } + + + /** + * A custom type of command line option corresponding to a short + * date value, e.g. . + */ + public static class ShortDateOption extends CmdLineParser.Option { + public ShortDateOption( char shortForm, String longForm ) { + super(shortForm, longForm, true); + } + protected Object parseValue( String arg, Locale locale ) + throws CmdLineParser.IllegalOptionValueException { + try { + DateFormat dateFormat = + DateFormat.getDateInstance(DateFormat.SHORT, locale); + return dateFormat.parse(arg); + } + catch (ParseException e) { + throw new CmdLineParser.IllegalOptionValueException(this, arg); + } + } + } + + 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); + } + +} diff --git a/3rdParty/jargs-1.0/examples/gnu/OptionParserSubclassTest.java b/3rdParty/jargs-1.0/examples/gnu/OptionParserSubclassTest.java new file mode 100644 index 0000000..551abf1 --- /dev/null +++ b/3rdParty/jargs-1.0/examples/gnu/OptionParserSubclassTest.java @@ -0,0 +1,71 @@ +package jargs.examples.gnu; + +import jargs.gnu.CmdLineParser; + +public class OptionParserSubclassTest { + + private static class MyOptionsParser extends CmdLineParser { + + public static final Option VERBOSE = new + CmdLineParser.Option.BooleanOption('v',"verbose"); + + public static final Option SIZE = new + CmdLineParser.Option.IntegerOption('s',"size"); + + public static final Option NAME = new + CmdLineParser.Option.StringOption('n',"name"); + + public static final Option FRACTION = new + CmdLineParser.Option.DoubleOption('f',"fraction"); + + public MyOptionsParser() { + super(); + addOption(VERBOSE); + addOption(SIZE); + addOption(NAME); + addOption(FRACTION); + } + } + + private static void printUsage() { + System.err.println("usage: prog [{-v,--verbose}] [{-n,--name} a_name]"+ + "[{-s,--size} a_number] [{-f,--fraction} a_float]"); + } + + public static void main( String[] args ) { + MyOptionsParser myOptions = new MyOptionsParser(); + + try { + myOptions.parse(args); + } + catch ( CmdLineParser.UnknownOptionException e ) { + System.err.println(e.getMessage()); + printUsage(); + System.exit(2); + } + catch ( CmdLineParser.IllegalOptionValueException e ) { + System.err.println(e.getMessage()); + printUsage(); + System.exit(2); + } + + CmdLineParser.Option[] allOptions = + new CmdLineParser.Option[] { MyOptionsParser.VERBOSE, + MyOptionsParser.NAME, + MyOptionsParser.SIZE, + MyOptionsParser.FRACTION }; + + for ( int j = 0; j + 4.0.0 + + jargs.gnu + jargs-gnu + 1.0 + jar + + jargs + http://jargs.sourceforge.net/ + + + UTF-8 + + + + + junit + junit + 4.11 + test + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + + + diff --git a/3rdParty/jargs-1.0/src/main/java/jargs/gnu/CmdLineParser.java b/3rdParty/jargs-1.0/src/main/java/jargs/gnu/CmdLineParser.java new file mode 100644 index 0000000..eddc658 --- /dev/null +++ b/3rdParty/jargs-1.0/src/main/java/jargs/gnu/CmdLineParser.java @@ -0,0 +1,526 @@ +package jargs.gnu; + +import java.text.NumberFormat; +import java.text.ParseException; +import java.util.Hashtable; +import java.util.Vector; +import java.util.Enumeration; +import java.util.Locale; + +/** + * Largely GNU-compatible command-line options parser. Has short (-v) and + * long-form (--verbose) option support, and also allows options with + * associated values (-d 2, --debug 2, --debug=2). Option processing + * can be explicitly terminated by the argument '--'. + * + * @author Steve Purcell + * @version $Revision: 1.10 $ + * @see jargs.examples.gnu.OptionTest + */ +public class CmdLineParser { + + /** + * Base class for exceptions that may be thrown when options are parsed + */ + public static abstract class OptionException extends Exception { + OptionException(String msg) { super(msg); } + } + + /** + * Thrown when the parsed command-line contains an option that is not + * recognised. getMessage() returns + * an error string suitable for reporting the error to the user (in + * English). + */ + public static class UnknownOptionException extends OptionException { + UnknownOptionException( String optionName ) { + this(optionName, "Unknown option '" + optionName + "'"); + } + + UnknownOptionException( String optionName, String msg ) { + super(msg); + this.optionName = optionName; + } + + /** + * @return the name of the option that was unknown (e.g. "-u") + */ + public String getOptionName() { return this.optionName; } + private String optionName = null; + } + + /** + * Thrown when the parsed commandline contains multiple concatenated + * short options, such as -abcd, where one is unknown. + * getMessage() returns an english human-readable error + * string. + * @author Vidar Holen + */ + public static class UnknownSuboptionException + extends UnknownOptionException { + private char suboption; + + UnknownSuboptionException( String option, char suboption ) { + super(option, "Illegal option: '"+suboption+"' in '"+option+"'"); + this.suboption=suboption; + } + public char getSuboption() { return suboption; } + } + + /** + * Thrown when the parsed commandline contains multiple concatenated + * short options, such as -abcd, where one or more requires a value. + * getMessage() returns an english human-readable error + * string. + * @author Vidar Holen + */ + public static class NotFlagException extends UnknownOptionException { + private char notflag; + + NotFlagException( String option, char unflaggish ) { + super(option, "Illegal option: '"+option+"', '"+ + unflaggish+"' requires a value"); + notflag=unflaggish; + } + + /** + * @return the first character which wasn't a boolean (e.g 'c') + */ + public char getOptionChar() { return notflag; } + } + + /** + * Thrown when an illegal or missing value is given by the user for + * an option that takes a value. getMessage() returns + * an error string suitable for reporting the error to the user (in + * English). + */ + public static class IllegalOptionValueException extends OptionException { + public IllegalOptionValueException( Option opt, String value ) { + super("Illegal value '" + value + "' for option " + + (opt.shortForm() != null ? "-" + opt.shortForm() + "/" : "") + + "--" + opt.longForm()); + this.option = opt; + this.value = value; + } + + /** + * @return the name of the option whose value was illegal (e.g. "-u") + */ + public Option getOption() { return this.option; } + + /** + * @return the illegal value + */ + public String getValue() { return this.value; } + private Option option; + private String value; + } + + /** + * Representation of a command-line option + */ + public static abstract class Option { + + protected Option( String longForm, boolean wantsValue ) { + this(null, longForm, wantsValue); + } + + protected Option( char shortForm, String longForm, + boolean wantsValue ) { + this(new String(new char[]{shortForm}), longForm, wantsValue); + } + + private Option( String shortForm, String longForm, boolean wantsValue ) { + if ( longForm == null ) + throw new IllegalArgumentException("Null longForm not allowed"); + this.shortForm = shortForm; + this.longForm = longForm; + this.wantsValue = wantsValue; + } + + public String shortForm() { return this.shortForm; } + + public String longForm() { return this.longForm; } + + /** + * Tells whether or not this option wants a value + */ + public boolean wantsValue() { return this.wantsValue; } + + public final Object getValue( String arg, Locale locale ) + throws IllegalOptionValueException { + if ( this.wantsValue ) { + if ( arg == null ) { + throw new IllegalOptionValueException(this, ""); + } + return this.parseValue(arg, locale); + } + else { + return Boolean.TRUE; + } + } + + /** + * Override to extract and convert an option value passed on the + * command-line + */ + protected Object parseValue( String arg, Locale locale ) + throws IllegalOptionValueException { + return null; + } + + private String shortForm = null; + private String longForm = null; + private boolean wantsValue = false; + + public static class BooleanOption extends Option { + public BooleanOption( char shortForm, String longForm ) { + super(shortForm, longForm, false); + } + public BooleanOption( String longForm ) { + super(longForm, false); + } + } + + /** + * An option that expects an integer value + */ + public static class IntegerOption extends Option { + public IntegerOption( char shortForm, String longForm ) { + super(shortForm, longForm, true); + } + public IntegerOption( String longForm ) { + super(longForm, true); + } + protected Object parseValue( String arg, Locale locale ) + throws IllegalOptionValueException { + try { + return new Integer(arg); + } + catch (NumberFormatException e) { + throw new IllegalOptionValueException(this, arg); + } + } + } + + /** + * An option that expects a long integer value + */ + public static class LongOption extends Option { + public LongOption( char shortForm, String longForm ) { + super(shortForm, longForm, true); + } + public LongOption( String longForm ) { + super(longForm, true); + } + protected Object parseValue( String arg, Locale locale ) + throws IllegalOptionValueException { + try { + return new Long(arg); + } + catch (NumberFormatException e) { + throw new IllegalOptionValueException(this, arg); + } + } + } + + /** + * An option that expects a floating-point value + */ + public static class DoubleOption extends Option { + public DoubleOption( char shortForm, String longForm ) { + super(shortForm, longForm, true); + } + public DoubleOption( String longForm ) { + super(longForm, true); + } + protected Object parseValue( String arg, Locale locale ) + throws IllegalOptionValueException { + try { + NumberFormat format = NumberFormat.getNumberInstance(locale); + Number num = (Number)format.parse(arg); + return new Double(num.doubleValue()); + } + catch (ParseException e) { + throw new IllegalOptionValueException(this, arg); + } + } + } + + /** + * An option that expects a string value + */ + public static class StringOption extends Option { + public StringOption( char shortForm, String longForm ) { + super(shortForm, longForm, true); + } + public StringOption( String longForm ) { + super(longForm, true); + } + protected Object parseValue( String arg, Locale locale ) { + return arg; + } + } + } + + /** + * Add the specified Option to the list of accepted options + */ + public final Option addOption( Option opt ) { + if ( opt.shortForm() != null ) + this.options.put("-" + opt.shortForm(), opt); + this.options.put("--" + opt.longForm(), opt); + return opt; + } + + /** + * Convenience method for adding a string option. + * @return the new Option + */ + public final Option addStringOption( char shortForm, String longForm ) { + return addOption(new Option.StringOption(shortForm, longForm)); + } + + /** + * Convenience method for adding a string option. + * @return the new Option + */ + public final Option addStringOption( String longForm ) { + return addOption(new Option.StringOption(longForm)); + } + + /** + * Convenience method for adding an integer option. + * @return the new Option + */ + public final Option addIntegerOption( char shortForm, String longForm ) { + return addOption(new Option.IntegerOption(shortForm, longForm)); + } + + /** + * Convenience method for adding an integer option. + * @return the new Option + */ + public final Option addIntegerOption( String longForm ) { + return addOption(new Option.IntegerOption(longForm)); + } + + /** + * Convenience method for adding a long integer option. + * @return the new Option + */ + public final Option addLongOption( char shortForm, String longForm ) { + return addOption(new Option.LongOption(shortForm, longForm)); + } + + /** + * Convenience method for adding a long integer option. + * @return the new Option + */ + public final Option addLongOption( String longForm ) { + return addOption(new Option.LongOption(longForm)); + } + + /** + * Convenience method for adding a double option. + * @return the new Option + */ + public final Option addDoubleOption( char shortForm, String longForm ) { + return addOption(new Option.DoubleOption(shortForm, longForm)); + } + + /** + * Convenience method for adding a double option. + * @return the new Option + */ + public final Option addDoubleOption( String longForm ) { + return addOption(new Option.DoubleOption(longForm)); + } + + /** + * Convenience method for adding a boolean option. + * @return the new Option + */ + public final Option addBooleanOption( char shortForm, String longForm ) { + return addOption(new Option.BooleanOption(shortForm, longForm)); + } + + /** + * Convenience method for adding a boolean option. + * @return the new Option + */ + public final Option addBooleanOption( String longForm ) { + return addOption(new Option.BooleanOption(longForm)); + } + + /** + * Equivalent to {@link #getOptionValue(Option, Object) getOptionValue(o, + * null)}. + */ + public final Object getOptionValue( Option o ) { + return getOptionValue(o, null); + } + + + /** + * @return the parsed value of the given Option, or null if the + * option was not set + */ + public final Object getOptionValue( Option o, Object def ) { + Vector v = (Vector)values.get(o.longForm()); + + if (v == null) { + return def; + } + else if (v.isEmpty()) { + return null; + } + else { + Object result = v.elementAt(0); + v.removeElementAt(0); + return result; + } + } + + + /** + * @return A Vector giving the parsed values of all the occurrences of the + * given Option, or an empty Vector if the option was not set. + */ + public final Vector getOptionValues( Option option ) { + Vector result = new Vector(); + + while (true) { + Object o = getOptionValue(option, null); + + if (o == null) { + return result; + } + else { + result.addElement(o); + } + } + } + + + /** + * @return the non-option arguments + */ + public final String[] getRemainingArgs() { + return this.remainingArgs; + } + + /** + * 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 specified locale is used for + * parsing options whose values might be locale-specific. + */ + public final void parse( String[] argv, Locale locale ) + 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. + + Vector otherArgs = new Vector(); + int position = 0; + this.values = new Hashtable(10); + while ( position < argv.length ) { + String curArg = argv[position]; + if ( curArg.startsWith("-") ) { + if ( curArg.equals("--") ) { // end of options + position += 1; + break; + } + String valueArg = null; + if ( curArg.startsWith("--") ) { // handle --arg=value + int equalsPos = curArg.indexOf("="); + if ( equalsPos != -1 ) { + valueArg = curArg.substring(equalsPos+1); + curArg = curArg.substring(0,equalsPos); + } + } else if(curArg.length() > 2) { // handle -abcd + for(int i=1; i3.5.0 - jargs - jargs - 1.0.0 + jargs.gnu + jargs-gnu + 1.0 org.apache.solr -- cgit v1.2.3-54-g00ecf