edu.mayo.bsi.ngsportal.server
Class GetOpts

java.lang.Object
  extended by edu.mayo.bsi.ngsportal.server.GetOpts

public class GetOpts
extends Object

A utility class to handle getting user options. A class that uses this must implement Usage, in order to inform the user of the command options if there's a problem with parsing the user's command line.

Version:
Revision: 1.1
Author:
Gregory Dougherty

Nested Class Summary
static class GetOpts.ArgType
          Enumerated Type to specify the type of argument (if any) any option has
static class GetOpts.OptType
          Enumerated Type to specify the type of option.
 
Field Summary
static String kArgumentSeparator
          Character that specifies how multiple arguments are separated in a return string
static char kNoShortArg
          Character that specifies that there is no short argument
 
Method Summary
static void addOption(char shortOption, String longOption, GetOpts.ArgType argument, GetOpts.OptType required)
           
static String[] parseArgs(String[] args, Usage target)
          Parse a command line, given the already added GetOpts descriptions
 void setValue(String value)
          Set the value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kNoShortArg

public static final char kNoShortArg
Character that specifies that there is no short argument

See Also:
Constant Field Values

kArgumentSeparator

public static final String kArgumentSeparator
Character that specifies how multiple arguments are separated in a return string

See Also:
Constant Field Values
Method Detail

setValue

public final void setValue(String value)
Set the value. If can take multiple values, and this is the second or greater time the option has had it's value set, add the value to the list of values for the option

Parameters:
value - the value to set

addOption

public static void addOption(char shortOption,
                             String longOption,
                             GetOpts.ArgType argument,
                             GetOpts.OptType required)
Parameters:
shortOption - Character of the option. '\0' if no short option
longOption - Name of the option begins with -- if also a long option version
argument - Does it take an argument
required - Is this option optional, or required

parseArgs

public static String[] parseArgs(String[] args,
                                 Usage target)
Parse a command line, given the already added GetOpts descriptions

Parameters:
args - The elements of the command line
target - Usage implementer to call if there's a problem
Returns:
Array of strings, or null if there was an error. The first n strings will be for the possible options, in the order they were specified. Null means the option wasn't in the command line, "" means it was, and did not have an argument, a non-empty string holds the argument that was with the option.