public class Getopt
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
class |
Getopt.OptionParseException |
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,java.lang.String> |
descriptions |
private java.util.Map<java.lang.String,java.lang.Integer> |
options |
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
optvals |
private java.util.List<java.lang.String> |
otherargs |
Constructor and Description |
---|
Getopt()
Constructor.
|
Getopt(java.util.Map<java.lang.String,java.lang.Integer> options,
java.util.Map<java.lang.String,java.lang.String> descriptions)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addOption(java.lang.String option,
int arguments,
java.lang.String description)
Add an option to the internal set, including the number of arguments and the
description.
|
java.util.List<java.lang.String> |
getArguments(java.lang.String option)
Gets the list of arguments for a given option, or null if the option wasn't
specified.
|
java.lang.String |
getDescriptionString()
Get a tabular description of all options and their descriptions, one per line.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getOptionValues()
Gets the set of all options specified, as well as the list of their arguments.
|
java.util.List<java.lang.String> |
getOtherArguments()
Gets the list arguments specified that were *not* options or their arguments, in
the order they were specified.
|
boolean |
hasOption(java.lang.String opt)
Determines whether or not the option was specified when the arguments were parsed.
|
static void |
main(java.lang.String[] args) |
void |
parse(java.lang.String[] args)
Do the parsing/validation.
|
private java.util.Map<java.lang.String,java.lang.Integer> options
private java.util.List<java.lang.String> otherargs
private java.util.Map<java.lang.String,java.lang.String> descriptions
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> optvals
public Getopt(java.util.Map<java.lang.String,java.lang.Integer> options, java.util.Map<java.lang.String,java.lang.String> descriptions)
options
- Map of options to parse. The key should be an option string (including
any initial dashes), and the value should be an Integer representing the number of
arguments to parse following the option.descriptions
- Map of option descriptions.public Getopt()
public java.util.List<java.lang.String> getOtherArguments()
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getOptionValues()
public boolean hasOption(java.lang.String opt)
public java.util.List<java.lang.String> getArguments(java.lang.String option)
option
- the optionpublic void addOption(java.lang.String option, int arguments, java.lang.String description)
option
- option string, including any leading dashesarguments
- number of argumentsdescription
- description of the optionpublic void parse(java.lang.String[] args) throws Getopt.OptionParseException
args
- arguments to parseGetopt.OptionParseException
- if a parse error occurs (the exception message will
have details)public java.lang.String getDescriptionString()
public static void main(java.lang.String[] args)