|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectConvenientGetopt
public class ConvenientGetopt
This class encapsulates the GNU Getopt library and makes it more convenient to use from Java programs. It hides the details of the parameter string syntax completely from the user, and provides the automatic display of usage information.
Field Summary | |
---|---|
static int |
NO_ARGUMENT
Option takes no arguments. |
static int |
OPTIONAL_ARGUMENT
Option takes an optional argument. |
static int |
REQUIRED_ARGUMENT
Option takes a required argument. |
Constructor Summary | |
---|---|
ConvenientGetopt(String progname,
String howToCall,
String docBelow)
Create new getopt object. |
Method Summary | |
---|---|
void |
addOption(char shortname,
int hasArg,
String defaultValue,
String description)
Add an option that has no long name. |
void |
addOption(char shortname,
String longname,
int hasArg,
String description,
String defaultValue)
Add an option that has a long name. |
List<String> |
getRemaining()
Retrieve those command-line arguments that don't belong to any option. |
String |
getValue(char shortname)
Retrieve the value of an option. |
String |
getValue(String longname)
Retrieve the value of an option. |
boolean |
hasOption(char shortname)
Check whether an option was present on the command line. |
boolean |
hasOption(String longname)
Check whether an option was present on the command line. |
void |
parse(String[] args)
Parse a command line. |
Methods inherited from class Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NO_ARGUMENT
public static final int OPTIONAL_ARGUMENT
public static final int REQUIRED_ARGUMENT
Constructor Detail |
---|
public ConvenientGetopt(String progname, String howToCall, String docBelow)
progname
- name of the program (for error message)howToCall
- description of program call syntax (or null)docBelow
- documentation that goes below the options in the usage message (or null)Method Detail |
---|
public void addOption(char shortname, int hasArg, String defaultValue, String description)
shortname
- short name of the option ('s' for option -s)hasArg
- does the option have arguments? (no, optional, required)defaultValue
- default value for the argumentdescription
- short description for the usage message.public void addOption(char shortname, String longname, int hasArg, String description, String defaultValue)
shortname
- short name of the option ('s' for option -s)longname
- long name of the option ("server" for option --server)hasArg
- does the option have arguments? (no, optional, required)defaultValue
- default value for the argumentdescription
- short description for the usage message.public void parse(String[] args)
args
- the command-line array that the main method got.public boolean hasOption(char shortname)
shortname
- the short name of the option
public boolean hasOption(String longname)
longname
- the long name of the option
public String getValue(String longname)
longname
- the long name of the option
public String getValue(char shortname)
shortname
- the short name of the option
public List<String> getRemaining()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |