net.jxta.impl.shell
Class GetOpt
java.lang.Object
|
+--net.jxta.impl.shell.GetOpt
- public class GetOpt
- extends java.lang.Object
This class provides the functionality for parsing command line
arguments (similar to getopt(3C)).
After constructing an instance of it, getNextOption() can be used
to get the next option. getOptionArg() can be used to get the argument for
that option. getNextOptionIndex() returns how many arguments are already
processed from the arguments list.
This class could be extended to handle the entire command line
instead of a pre-processed command line. The problem with that
is handling pipes and redirects, but it would make options
parsing easier.
Constructor Summary |
GetOpt(java.lang.String[] argv,
java.lang.String optionString)
Constructor |
Method Summary |
int |
getNextOption()
Returns the next valid option. |
int |
getNextOptionIndex()
Returns how many arguments are already processed by the getNextOption()
function. |
java.lang.String |
getOptionArg()
Returns the argument for the option being handled. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
GetOpt
public GetOpt(java.lang.String[] argv,
java.lang.String optionString)
- Constructor
- Parameters:
argv
- -- Array of string arguments.optionString
- -- contains the option letters that
will be recognized;
if a letter is followed by a colon,
the option is expected to have an argument.
if a letter is followed by a semi-colon,
the argument to the letter is optional.
e.g. abdf:e (legal arguments are a,b,d,f,e. f option requires a argument.
getNextOption
public int getNextOption()
throws java.lang.IllegalArgumentException
- Returns the next valid option.
Throws an IllegalArgumentException
a) if option is not valid or
b) an option required an argument and is not provided
Returns -1 if no more options left.
getOptionArg
public java.lang.String getOptionArg()
- Returns the argument for the option being handled.
getNextOptionIndex
public int getNextOptionIndex()
- Returns how many arguments are already processed by the getNextOption()
function. The other way to look at it is what argument is going to be
processed by getNextOption() method next.