public class Getopts
extends java.lang.Object
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 and Description |
---|
Getopts(java.lang.String flags,
java.lang.String[] args)
Wrapper Constructor
|
Getopts(java.lang.String progname,
java.lang.String[] args,
java.lang.String flags)
Wrapper Constructor
|
Getopts(java.lang.String progname,
java.lang.String flags,
java.lang.String[] args)
Basic class constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String[] |
argList()
Method to return an array of the actual arguments of the
command line invocation.
|
int |
getopt() |
java.lang.String |
getOptarg() |
int |
getOptind() |
java.lang.String |
getOption(java.lang.Character sw)
getOption
|
java.lang.String |
getOption(int sw)
getOption
|
int |
getOptopt() |
OptSwitch |
getSwitch(java.lang.Character sw)
method to return the OptSwitch object associated with the
'sw' argument.
|
protected void |
initialize(java.lang.String progname,
java.lang.String flags,
java.lang.String[] args) |
static void |
main(java.lang.String[] args)
method for class testing.
|
void |
setOpterr(boolean b) |
java.util.Enumeration |
swList()
Method to return an Enumeration of the switches
that the Getopts object is able to parse (according
to its initialization).
|
public Getopts(java.lang.String flags, java.lang.String[] args) throws InvalidSwitch
flags
- a string with the valid switch namesargs
- array of strings (usually args)
InvalidSwitch
- thrown when invalid options are found
public Getopts(java.lang.String progname, java.lang.String flags, java.lang.String[] args) throws InvalidSwitch
progname
- program name for producing error messagesflags
- a string with the valid switch namesargs
- array of strings (usually args)
InvalidSwitch
- thrown when invalid options are found
public Getopts(java.lang.String progname, java.lang.String[] args, java.lang.String flags)
progname
- program name for producing error messagesflags
- a string with the valid switch namesargs
- array of strings (usually args)
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()
public java.lang.String[] argList()
protected void initialize(java.lang.String progname, java.lang.String flags, java.lang.String[] args) throws InvalidSwitch
InvalidSwitch
public static void main(java.lang.String[] args)
java Getopts "option set" arg0 arg1 ... argn
args
- arguments passedpublic int getopt()
public java.lang.String getOptarg()
public void setOpterr(boolean b)
public int getOptind()
public int getOptopt()