support143
Class Args

java.lang.Object
  |
  +--support143.Args
Direct Known Subclasses:
IntegerArgs

public class Args
extends java.lang.Object

Args class for managing command line arguments. A command line argument can be a flag, which is either present or not, or "anything else".


Field Summary
protected  java.util.HashMap flags
           
protected  java.util.ArrayList unflaggedArgs
           
 
Constructor Summary
Args(java.lang.String mainName, java.lang.String[] commandLine)
          Sole Constructor.
 
Method Summary
 void addCommand(java.lang.String arg, java.lang.String helpMsg)
          Creates a given command and associates it with the help message.
protected  boolean consumeArgument(java.lang.String a)
          Consumes (and processes) a single argument.
protected  boolean consumeFlaggedArgument(java.lang.String f)
          Consumes a flagged argument so that its presence can later be queried.
protected  boolean consumeUnflaggedArgument(java.lang.String u)
          Consumes an unflagged argument.
 void expectUnflaggedArguments(java.lang.String kind)
          Allows for arguments without "-"'s
 java.lang.String[] getNonFlaggedArguments()
          Fetches all non flagged arguments.
 int getRemainingCommandLineArguments()
          Computes how many command line arguments remain for parsing.
 void help()
          Shows a help message to the console.
 void help(java.lang.String msg)
          Shows a prefixed help message to the console.
 boolean isFlagPresent(java.lang.String f)
          Checks if a given flag is present in the command line.
 boolean parseCommandLine()
          Parses any unparsed command line arguments.
protected  void setHelp(java.lang.String cmd, java.lang.String help)
          Associates a help message with a command.
protected  java.lang.String shiftCommandLine()
          Shifts left the command line, dropping the first argument into oblivion.
protected  void showHelp()
          Shows help messages.
 void showUsage()
          Displays invocation template.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

flags

protected java.util.HashMap flags

unflaggedArgs

protected java.util.ArrayList unflaggedArgs
Constructor Detail

Args

public Args(java.lang.String mainName,
            java.lang.String[] commandLine)
Sole Constructor.

Parameters:
mainName - name of driver module
commandLine - that should be parsed!
Method Detail

setHelp

protected void setHelp(java.lang.String cmd,
                       java.lang.String help)
Associates a help message with a command.

Parameters:
cmd - command
help - help message

expectUnflaggedArguments

public void expectUnflaggedArguments(java.lang.String kind)
Allows for arguments without "-"'s

Parameters:
kind - generic printable name for args

addCommand

public void addCommand(java.lang.String arg,
                       java.lang.String helpMsg)
Creates a given command and associates it with the help message.

Parameters:
arg - flagged argument (eg, "-t"). Includes the dash (-)
helpMsg - any associated help text

shiftCommandLine

protected java.lang.String shiftCommandLine()
Shifts left the command line, dropping the first argument into oblivion.

Returns:
dropped command line argument. null if command line empty.

getRemainingCommandLineArguments

public int getRemainingCommandLineArguments()
Computes how many command line arguments remain for parsing.

Returns:
number of unparsed arguments.

consumeFlaggedArgument

protected boolean consumeFlaggedArgument(java.lang.String f)
Consumes a flagged argument so that its presence can later be queried.

Parameters:
f - flag
Returns:
true if flag was expected, falseotherwise.

consumeUnflaggedArgument

protected boolean consumeUnflaggedArgument(java.lang.String u)
Consumes an unflagged argument.

Parameters:
u - the unflagged argument.
Returns:
trueif we expected unflagged arguments. else false

consumeArgument

protected boolean consumeArgument(java.lang.String a)
Consumes (and processes) a single argument.

Parameters:
a - argument
Returns:
true if argument was valid, false otherwise.

parseCommandLine

public boolean parseCommandLine()
Parses any unparsed command line arguments.

Returns:
trueif args are consistent with expectation. else false

isFlagPresent

public boolean isFlagPresent(java.lang.String f)
Checks if a given flag is present in the command line.

Parameters:
f - flag to check. Should include the "-"
Returns:
true if arg present. else false.

getNonFlaggedArguments

public java.lang.String[] getNonFlaggedArguments()
Fetches all non flagged arguments.

Returns:
array of Strings containing non flagged arguments.

showUsage

public void showUsage()
Displays invocation template.


showHelp

protected void showHelp()
Shows help messages.


help

public void help(java.lang.String msg)
Shows a prefixed help message to the console.

Parameters:
msg - any prefixing message which should be included.

help

public void help()
Shows a help message to the console.