edu.cmu.minorthird.util
Class JointCommandLineProcessor

java.lang.Object
  extended by edu.cmu.minorthird.util.JointCommandLineProcessor
All Implemented Interfaces:
CommandLineProcessor

public class JointCommandLineProcessor
extends java.lang.Object
implements CommandLineProcessor

A lightweight command-line processing tool.

Author:
William Cohen

Nested Class Summary
 
Nested classes/interfaces inherited from interface edu.cmu.minorthird.util.CommandLineProcessor
CommandLineProcessor.Configurable
 
Constructor Summary
JointCommandLineProcessor(CommandLineProcessor[] subprocessor)
           
 
Method Summary
 int consumeArguments(java.lang.String[] args, int startPos)
          Try to consume a the command-line argument at position i.
 void help()
           
static void main(java.lang.String[] args)
           
 void processArguments(java.lang.String[] args)
          Loop thru the command-line arguments.
 boolean shouldTerminate()
          Specifies whether the commandline processing should terminate.
 void usage()
          Give usage() information.
 void usage(java.lang.String errorMessage)
          Prints errorMessage and then calls usage().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JointCommandLineProcessor

public JointCommandLineProcessor(CommandLineProcessor[] subprocessor)
Method Detail

shouldTerminate

public boolean shouldTerminate()
Description copied from interface: CommandLineProcessor
Specifies whether the commandline processing should terminate. For example, if the usage is to be displayed, we should ignore other arguments and terminate.

Specified by:
shouldTerminate in interface CommandLineProcessor

processArguments

public final void processArguments(java.lang.String[] args)
Description copied from interface: CommandLineProcessor
Loop thru the command-line arguments. Option pairs like "-foo bar" should cause a call to x.foo("bar"), where x is this CommandLineProcessor. Options like "-gorp" cause a call to x.gorp(). Options without corresponding methods are considered errors. If an error occurs, then an IllegalArgumentException is thrown.

If function like -foo happens to return a non-null CommandLineProcessor, that processor is invoked on the arguments immediately after foo. This allows one CommandLineProcessor to pass command-line options to a second one. For instance, if x and y are CommandLineProcessors, x has an method colorOpts() that returns y, and y has methods background(String s) and foreground(String t) then the command line sequence -colorOpts -background blue -foreground red would call the expected methods of y.

The optional "-config FILE" should cause a Properties object to be loaded from FILE, and the property/value pairs in the Properties object to be treated as if they were option/argument pairs. The order of lines in the property file may not be preserved, however, and duplicated keys will be ignored.

For instance, calling -config FILE for a FILE containing

baz=
foo=bar
would be the same as the command options -foo bar -baz or possibly -baz -foo bar

Specified by:
processArguments in interface CommandLineProcessor

consumeArguments

public final int consumeArguments(java.lang.String[] args,
                                  int startPos)
Description copied from interface: CommandLineProcessor
Try to consume a the command-line argument at position i. Return the number of arguments successfully consumed.

Specified by:
consumeArguments in interface CommandLineProcessor

usage

public final void usage(java.lang.String errorMessage)
Description copied from interface: CommandLineProcessor
Prints errorMessage and then calls usage().

Specified by:
usage in interface CommandLineProcessor

usage

public final void usage()
Description copied from interface: CommandLineProcessor
Give usage() information.

Specified by:
usage in interface CommandLineProcessor

help

public final void help()

main

public static void main(java.lang.String[] args)