|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdods.util.Getopts
public class Getopts
A class for achieving getopts() functionality.
Loosely based on perl5's getopt/Std.pm.
The object is instantiated with a 'flags' String that is the composed of the set of switches allowed to be passed, and the 'args' String array that has to be parsed opposite the 'flags' string.
new Getopts("oif:", args) -o, -i are boolean flags, -f takes an argumentThe class processes single-character switches with switch clustering.
The list of valid switches is accessible through the 'swList()' method, which returns an Enumeration of the switch names.
A local array including the arguments from the 'args' array that was passed as an argument but are the actual command line arguments is generated and is accessible through the 'argList()' method.
Options switch content fields can be accessible through the 'OptSwitch' class.
OptSwitch
,
Enumeration
Constructor Summary | |
---|---|
Getopts(java.lang.String flags,
java.lang.String[] args)
Basic class constructor. |
Method Summary | |
---|---|
java.lang.String[] |
argList()
Method to return an array of the actual arguments of the command line invocation. |
java.lang.String |
getOption(java.lang.Character sw)
getOption |
java.lang.String |
getOption(int sw)
getOption |
OptSwitch |
getSwitch(java.lang.Character sw)
method to return the OptSwitch object associated with the 'sw' argument. |
static void |
main(java.lang.String[] args)
method for class testing. |
java.util.Enumeration |
swList()
Method to return an Enumeration of the switches that the Getopts object is able to parse (according to its initialization). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Getopts(java.lang.String flags, java.lang.String[] args) throws InvalidSwitch
String array 'args' is passed and is parsed according to the flags.
flags
- a string with the valid switch namesargs[]
- array of strings (usually args)
InvalidSwitch
- thrown when invalid options are found
Method Detail |
---|
public OptSwitch getSwitch(java.lang.Character sw)
sw
- switch whose class is requested
public java.lang.String getOption(java.lang.Character sw)
sw
- Character switch whose option is requestedpublic java.lang.String getOption(int sw)
sw
- int value switch whose option is requestedpublic java.util.Enumeration swList()
May be later used to step through the OptSwitch objects.
public java.lang.String[] argList()
public static void main(java.lang.String[] args) throws InvalidSwitch
Invocation:
java Getopts "option set" arg0 arg1 ... argn
InvalidSwitch
- thrown when invalid options are found
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |