| java.lang.Object jimm.util.Getopts
Getopts | public class Getopts (Code) | | Getopts is similar to the UN*X getopt() system call. It parses an array of
Strings (usually the command line), looking for specified option flags and
values.
An instance of Getopts parses the whole args list at once, and stores the
option flags and values that it finds.
author: Jim Menard, author: jimm@io.com |
Constructor Summary | |
public | Getopts(String optionListString, String[] args) This constructor takes a list of legal options and a list of (usually
command line) arguments. |
Method Summary | |
public int | argc() Return the number of non-option args. | public String[] | args() Return the remaining command-line arguments. | public String | argv(int index) Return a command line argument or "" if argv is
null . | public boolean | error() Return true if there was an error while parsing the command line. | public boolean | hasOption(char c) Returns existence of an option. | public String | option(char c) Return an option or, if missing, the empty string. | public String | option(char c, String defaultValue) Return an option or, if missing, a default value. |
errorFlag | boolean errorFlag(Code) | | |
Getopts | public Getopts(String optionListString, String[] args)(Code) | | This constructor takes a list of legal options and a list of (usually
command line) arguments. Each option in optionListString may be followed
by a ':' to signify that option takes an argument.
Parameters: optionListString - option chars with optional ':' specifying arg.For example, "ab:c" specifies three options, a, b, and c. Option b takesa (required) argument. Parameters: args - array of command line arguments |
argc | public int argc()(Code) | | Return the number of non-option args.
|
argv | public String argv(int index)(Code) | | Return a command line argument or "" if argv is
null . Index starts at 0.
Parameters: index - which argument to return the index'th arg or "" if argv is null |
error | public boolean error()(Code) | | Return true if there was an error while parsing the command line.
|
hasOption | public boolean hasOption(char c)(Code) | | Returns existence of an option.
true of option 'c' exists, else return false. Parameters: c - any character |
option | public String option(char c)(Code) | | Return an option or, if missing, the empty string.
option string, or "" if error or option has no argument Parameters: c - the option whose value is returned |
option | public String option(char c, String defaultValue)(Code) | | Return an option or, if missing, a default value.
option string, or defaultValue if error or option has no argument Parameters: c - the option whose value is returned Parameters: defaultValue - the value to return if there is no such option |
|
|