diff --git a/.gitignore b/.gitignore
index 08d3e3d..da72d7c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
/classes
/doc
-/lib/jargs*.jar
\ No newline at end of file
+/lib/jargs*.jar
+*~
diff --git a/LICENCE b/LICENCE
index 509c1b7..f79cc31 100644
--- a/LICENCE
+++ b/LICENCE
@@ -2,6 +2,7 @@ Copyright (c) 2001-2003 Steve Purcell.
Copyright (c) 2002 Vidar Holen.
Copyright (c) 2002 Michal Ceresna.
Copyright (c) 2005 Ewan Mellor.
+Copyright (c) 2010-2012 penSec.IT UG (haftungsbeschränkt).
All rights reserved.
diff --git a/README.md b/README.md
index 12b75a6..0f8175a 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,7 @@ JArgs command-line argument parsing library
- Copyright (c) 2002 Vidar Holen.
- Copyright (c) 2002 Michal Ceresna.
- Copyright (c) 2005 Ewan Mellor.
+- Copyright (c) 2010-2012 penSec.IT UG (haftungsbeschränkt).
All rights reserved.
@@ -21,7 +22,7 @@ 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 (3.7 & 4.3.1), by Eric Gamma, et al, from http://www.junit.org/.
JUnit is used to run the unit tests, and is not needed to run the library
itself.
@@ -45,8 +46,9 @@ Documentation
-------------
The main documentation is the detailed worked example in
-`src/jargs/examples/gnu/OptionTest.java`, plus the generated API documentation
-in `doc/api/`.
+`src/jargs/examples/gnu/OptionTest.java` (old Java 1.1 API),
+`src/jargs/examples/gnu/OptionTest5.java` (new Java 1.5 API), plus the generated
+API documentation in `doc/api/`.
Package contents
diff --git a/build.xml b/build.xml
index 3697ec9..7631198 100644
--- a/build.xml
+++ b/build.xml
@@ -3,15 +3,15 @@
-
-
+
+
-
+
-
+
+
@@ -30,7 +30,7 @@ Purcell. Copyright © 2002 Vidar Holen. Copyright © 2002 Micha
-
+
@@ -62,9 +62,13 @@ Purcell. Copyright © 2002 Vidar Holen. Copyright © 2002 Micha
+ classpath="${build.classes}:${junit3.jar}:${java.class.path}">
+
+
+
@@ -98,7 +102,7 @@ Purcell. Copyright © 2002 Vidar Holen. Copyright © 2002 Micha
footer="${javadoc.header}"
bottom="${javadoc.bottom}">
-
+
diff --git a/src/jargs/examples/gnu/AutoHelpParser.java b/src/jargs/examples/gnu/AutoHelpParser.java
index f42ec5f..f008450 100644
--- a/src/jargs/examples/gnu/AutoHelpParser.java
+++ b/src/jargs/examples/gnu/AutoHelpParser.java
@@ -1,3 +1,35 @@
+/**
+ * Copyright (c) 2001-2003 Steve Purcell.
+ * Copyright (c) 2002 Vidar Holen.
+ * Copyright (c) 2002 Michal Ceresna.
+ * Copyright (c) 2005 Ewan Mellor.
+ * Copyright (c) 2010-2012 penSec.IT UG (haftungsbeschränkt).
+ *
+ * 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.
+ */
+
package jargs.examples.gnu;
import jargs.gnu.CmdLineParser;
diff --git a/src/jargs/examples/gnu/AutoHelpParser5.java b/src/jargs/examples/gnu/AutoHelpParser5.java
new file mode 100644
index 0000000..1b85c5e
--- /dev/null
+++ b/src/jargs/examples/gnu/AutoHelpParser5.java
@@ -0,0 +1,117 @@
+/**
+ * Copyright (c) 2001-2003 Steve Purcell.
+ * Copyright (c) 2002 Vidar Holen.
+ * Copyright (c) 2002 Michal Ceresna.
+ * Copyright (c) 2005 Ewan Mellor.
+ * Copyright (c) 2010-2012 penSec.IT UG (haftungsbeschränkt).
+ *
+ * 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.
+ */
+
+package jargs.examples.gnu;
+
+import jargs.gnu.CmdLineParser;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This example shows how to dynamically create basic output for a --help option.
+ */
+public class AutoHelpParser5 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 (String help : optionHelpStrings) {
+ System.err.println(help);
+ }
+ }
+
+ public static void main(String[] args) {
+ AutoHelpParser5 parser = new AutoHelpParser5();
+ 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 = parser.getOptionValue(verbose);
+ Integer sizeValue = parser.getOptionValue(size);
+ String nameValue = parser.getOptionValue(name);
+ Double fractionValue = 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/src/jargs/examples/gnu/CustomOptionTest.java b/src/jargs/examples/gnu/CustomOptionTest.java
index 2a1c45f..5b6bd8a 100644
--- a/src/jargs/examples/gnu/CustomOptionTest.java
+++ b/src/jargs/examples/gnu/CustomOptionTest.java
@@ -1,3 +1,35 @@
+/**
+ * Copyright (c) 2001-2003 Steve Purcell.
+ * Copyright (c) 2002 Vidar Holen.
+ * Copyright (c) 2002 Michal Ceresna.
+ * Copyright (c) 2005 Ewan Mellor.
+ * Copyright (c) 2010-2012 penSec.IT UG (haftungsbeschränkt).
+ *
+ * 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.
+ */
+
package jargs.examples.gnu;
import jargs.gnu.CmdLineParser;
diff --git a/src/jargs/examples/gnu/CustomOptionTest5.java b/src/jargs/examples/gnu/CustomOptionTest5.java
new file mode 100644
index 0000000..a088d49
--- /dev/null
+++ b/src/jargs/examples/gnu/CustomOptionTest5.java
@@ -0,0 +1,104 @@
+/**
+ * Copyright (c) 2001-2003 Steve Purcell.
+ * Copyright (c) 2002 Vidar Holen.
+ * Copyright (c) 2002 Michal Ceresna.
+ * Copyright (c) 2005 Ewan Mellor.
+ * Copyright (c) 2010-2012 penSec.IT UG (haftungsbeschränkt).
+ *
+ * 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.
+ */
+
+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 CustomOptionTest5 {
+
+ 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);
+ }
+
+ @Override
+ protected Date 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 = 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/src/jargs/examples/gnu/OptionParserSubclassTest.java b/src/jargs/examples/gnu/OptionParserSubclassTest.java
index 551abf1..9b10dd1 100644
--- a/src/jargs/examples/gnu/OptionParserSubclassTest.java
+++ b/src/jargs/examples/gnu/OptionParserSubclassTest.java
@@ -1,3 +1,35 @@
+/**
+ * Copyright (c) 2001-2003 Steve Purcell.
+ * Copyright (c) 2002 Vidar Holen.
+ * Copyright (c) 2002 Michal Ceresna.
+ * Copyright (c) 2005 Ewan Mellor.
+ * Copyright (c) 2010-2012 penSec.IT UG (haftungsbeschränkt).
+ *
+ * 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.
+ */
+
package jargs.examples.gnu;
import jargs.gnu.CmdLineParser;
diff --git a/src/jargs/examples/gnu/OptionParserSubclassTest5.java b/src/jargs/examples/gnu/OptionParserSubclassTest5.java
new file mode 100644
index 0000000..4d5c543
--- /dev/null
+++ b/src/jargs/examples/gnu/OptionParserSubclassTest5.java
@@ -0,0 +1,94 @@
+/**
+ * Copyright (c) 2001-2003 Steve Purcell.
+ * Copyright (c) 2002 Vidar Holen.
+ * Copyright (c) 2002 Michal Ceresna.
+ * Copyright (c) 2005 Ewan Mellor.
+ * Copyright (c) 2010-2012 penSec.IT UG (haftungsbeschränkt).
+ *
+ * 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.
+ */
+
+package jargs.examples.gnu;
+
+import jargs.gnu.CmdLineParser;
+
+public class OptionParserSubclassTest5 {
+
+ 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 < allOptions.length; ++j) {
+ System.out.println(allOptions[j].longForm() + ": "
+ + myOptions.getOptionValue(allOptions[j]));
+ }
+
+ String[] otherArgs = myOptions.getRemainingArgs();
+ System.out.println("remaining args: ");
+ for (int i = 0; i < otherArgs.length; ++i) {
+ System.out.println(otherArgs[i]);
+ }
+ System.exit(0);
+ }
+}
diff --git a/src/jargs/examples/gnu/OptionTest.java b/src/jargs/examples/gnu/OptionTest.java
index f09f6be..c84bafa 100644
--- a/src/jargs/examples/gnu/OptionTest.java
+++ b/src/jargs/examples/gnu/OptionTest.java
@@ -1,10 +1,41 @@
-package jargs.examples.gnu;
+/**
+ * Copyright (c) 2001-2003 Steve Purcell.
+ * Copyright (c) 2002 Vidar Holen.
+ * Copyright (c) 2002 Michal Ceresna.
+ * Copyright (c) 2005 Ewan Mellor.
+ * Copyright (c) 2010-2012 penSec.IT UG (haftungsbeschränkt).
+ *
+ * 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.
+ */
-import java.util.Enumeration;
-import java.util.Vector;
+package jargs.examples.gnu;
import jargs.gnu.CmdLineParser;
+import java.util.Collection;
+import java.util.Iterator;
public class OptionTest {
@@ -91,7 +122,7 @@ public static void main( String[] args ) {
// once. In this case, you may get all the values specified by the
// user, as a Vector:
- Vector fractionValues = parser.getOptionValues(fraction);
+ Collection