com.charliedog.argv
Class ArgumentParser

java.lang.Object
  |
  +--com.charliedog.argv.ArgumentParser

public class ArgumentParser
extends java.lang.Object

A parser for processing command line arguments. It is typically used as such:

     // Initialize arguments that may appear in the command line. By convention,
     // '-help' simply prints the command line usage and exits.

     StringArgument destination = new StringArgument( "-dest", "localhost", "Destination for request tests" );
     BooleanArgument help = new BooleanArgument( "-help", "Describe command line args" );

     // Initialize and invoke the parser. Note that arguments not consumed during
     // the parse are returned in case they may be subject to additional processing,
     // etc. Variable 'args' is assumed to contain the String array passed to main().

     ArgumentParser parser = new ArgumentParser();
     parser.addArgument( destination );
     parser.addArgument( skipClasses );
     parser.addArgument( skipRequests );
     List extra = parser.parse( args );

     // For this application, extra arguments will be treated as a usage error.

     if( !extra.isEmpty() || help.getValue())
     {
         PrintWriter out = new PrintWriter( System.out );
         parser.printUsage( out );
         out.close();
         System.exit( 0 );
     }
 

See Also:
BooleanArgument, StringArgument

Constructor Summary
ArgumentParser()
           
 
Method Summary
 void addArgument(Argument arg)
          Add a new argument to be taken into consideration during the next parse.
static void main(java.lang.String[] ignored)
          Test driver.
 java.util.List parse(java.lang.String[] args)
          Parses the given argument list according to all Arguments registered with this parser.
 void printUsage(java.io.PrintWriter out)
          Dumps the usage of each registered argument to out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArgumentParser

public ArgumentParser()
Method Detail

addArgument

public void addArgument(Argument arg)
Add a new argument to be taken into consideration during the next parse. Behavior when an argument is added multiple times or if multiple arguments share the same flag is undefined.


printUsage

public void printUsage(java.io.PrintWriter out)
Dumps the usage of each registered argument to out.


parse

public java.util.List parse(java.lang.String[] args)
Parses the given argument list according to all Arguments registered with this parser. Returns any arguments not consumed by the parse.


main

public static void main(java.lang.String[] ignored)
Test driver.