jargs-1.0/ 0000755 0001752 0001752 00000000000 10512022420 012272 5 ustar debyann debyann jargs-1.0/doc/ 0000755 0001752 0001752 00000000000 10512022226 013043 5 ustar debyann debyann jargs-1.0/doc/.cvsignore 0000644 0001752 0001752 00000000004 07741764621 015063 0 ustar debyann debyann api
jargs-1.0/doc/CHANGES 0000644 0001752 0001752 00000004151 10225321751 014045 0 ustar debyann debyann 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.
jargs-1.0/.cvsignore 0000644 0001752 0001752 00000000060 10225760132 014300 0 ustar debyann debyann classes
.classpath
.project
jargs.ipr
jargs.iws
jargs-1.0/LICENCE 0000644 0001752 0001752 00000003071 10225316242 013271 0 ustar debyann debyann 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.
jargs-1.0/README 0000644 0001752 0001752 00000003320 10225760076 013171 0 ustar debyann debyann 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.
jargs-1.0/TODO 0000644 0001752 0001752 00000000120 10225774517 013001 0 ustar debyann debyann JArgs to-do list
================
Nothing! (Fate, consider yourself tempted.)
jargs-1.0/build.xml 0000644 0001752 0001752 00000006565 10225316746 014151 0 ustar debyann debyann
jargs-1.0/src/ 0000755 0001752 0001752 00000000000 10225775322 013102 5 ustar debyann debyann jargs-1.0/src/jargs/ 0000755 0001752 0001752 00000000000 10225775323 014211 5 ustar debyann debyann jargs-1.0/src/jargs/examples/ 0000755 0001752 0001752 00000000000 10225775322 016026 5 ustar debyann debyann jargs-1.0/src/jargs/examples/gnu/ 0000755 0001752 0001752 00000000000 10225775322 016617 5 ustar debyann debyann jargs-1.0/src/jargs/examples/gnu/AutoHelpParser.java 0000644 0001752 0001752 00000006011 10145372027 022352 0 ustar debyann debyann 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);
}
}
jargs-1.0/src/jargs/examples/gnu/CustomOptionTest.java 0000644 0001752 0001752 00000004456 07633365006 023001 0 ustar debyann debyann 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);
}
}
jargs-1.0/src/jargs/examples/gnu/OptionParserSubclassTest.java 0000644 0001752 0001752 00000004353 07633365006 024457 0 ustar debyann debyann 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