org.limitless.util
Class CommandLineArgumentParser

java.lang.Object
  extended by org.limitless.util.CommandLineArgumentParser

public class CommandLineArgumentParser
extends java.lang.Object

This class trivializes the parsing of command-line arguments that obey the following structure: --flag - the presence of this stands alone -option value - this is an option with a single value following Anything else is an argument. Arguments are always in order. This class allows no means to determine what intermix of options, flags, and arguments there were, but the ordering relative to their same type is maintained.

Author:
Brian Jones, Brian Sanders

Nested Class Summary
static class CommandLineArgumentParser.BasicDetailsBuilder
          Basic command line argument builder.
static class CommandLineArgumentParser.BasicParseStrategy
           
static class CommandLineArgumentParser.DefaultDetailsBuilder
          Default command line argument builder.
static class CommandLineArgumentParser.Details
          This holds the processed set of command line arguments with no leading dashes on anything.
static interface CommandLineArgumentParser.DetailsBuilder
           
static class CommandLineArgumentParser.Option
          This holds option name and value, with the leading "-" stripped from the name.
static class CommandLineArgumentParser.ParseException
          This exception class is used when a parse rule is violated.
 
Field Summary
private static org.apache.log4j.Logger logger
           
 
Constructor Summary
CommandLineArgumentParser()
           
 
Method Summary
static void main(java.lang.String[] args)
          main() method for testing purposes.
 CommandLineArgumentParser.Details parse(java.lang.String[] args)
          Calls the parse() method using the default Details builder (see above) and the basic parse strategy.
 CommandLineArgumentParser.Details parse(java.lang.String[] args, CommandLineArgumentParser.DetailsBuilder builder)
          Calls the parse() method using the specified Details builder and the basic parse strategy.
 CommandLineArgumentParser.Details parse(java.lang.String[] args, CommandLineArgumentParser.DetailsBuilder builder, CommandLineArgumentParser.BasicParseStrategy strategy)
          Call this to parse the command line arguments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static org.apache.log4j.Logger logger
Constructor Detail

CommandLineArgumentParser

public CommandLineArgumentParser()
Method Detail

parse

public CommandLineArgumentParser.Details parse(java.lang.String[] args,
                                               CommandLineArgumentParser.DetailsBuilder builder,
                                               CommandLineArgumentParser.BasicParseStrategy strategy)
                                        throws CommandLineArgumentParser.ParseException
Call this to parse the command line arguments. The method will return a Details object containing all arguments, options, and flags, sorted into the appropriate variables (see Details definition). The Details object will be constructed by the specified builder object using the specified parse Strategy Throws a ParseException if there is no argument specified after an option, or if an empty option name is empty.

Parameters:
args -
builder -
strategy -
Returns:
Details
Throws:
CommandLineArgumentParser.ParseException

parse

public CommandLineArgumentParser.Details parse(java.lang.String[] args,
                                               CommandLineArgumentParser.DetailsBuilder builder)
                                        throws CommandLineArgumentParser.ParseException
Calls the parse() method using the specified Details builder and the basic parse strategy.

Parameters:
args -
builder -
Returns:
Details
Throws:
CommandLineArgumentParser.ParseException

parse

public CommandLineArgumentParser.Details parse(java.lang.String[] args)
                                        throws CommandLineArgumentParser.ParseException
Calls the parse() method using the default Details builder (see above) and the basic parse strategy.

Throws:
CommandLineArgumentParser.ParseException
See Also:
CommandLineArgumentParser.DefaultDetailsBuilder

main

public static void main(java.lang.String[] args)
main() method for testing purposes.

Parameters:
args -


Copyright © 1995, 2004 Limitless Knowledge Association, All Rights Reserved.