public class Flags
extends java.lang.Object
It can be used also for generating a "Usage" message with the list and description of all program options/parameters already parsed.
Example of command-line list:
Strings are of four types:
In the example above, '-a val2' and '--beta val3' are options, '-h' and '-v' are flags, while 'val1' and 'val4' are parameters.
Modifier and Type | Field and Description |
---|---|
static boolean |
FIRST_PARAMS_THEN_OPTIONS
First writes parameters, then options
|
static java.lang.String |
OPTIONAL_PARAM
Optional parameter
|
static java.lang.String |
PARAM
Parameter
|
static java.lang.String |
TAB1
Tab string for indenting all lines following the first "Usage" line.
|
static java.lang.String |
TAB2
Tab string for indenting all lines following "where:" and "Options:"
|
static java.lang.String |
TAB3
Tab string between the 'opt-param' part and the 'description' part
|
Constructor and Description |
---|
Flags(java.lang.String[] args)
Creates options.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Boolean |
getBoolean(java.lang.String tag,
java.lang.Boolean default_value,
java.lang.String description)
Parses the array of string for a given 'boolean option'.
|
boolean |
getBoolean(java.lang.String tag,
java.lang.String description)
Parses the array of string for a given 'boolean option'.
|
double |
getDouble(java.lang.String tag,
java.lang.String param,
double default_value,
java.lang.String description)
Parses the array of string for a given double option/parameter.
|
float |
getFloat(java.lang.String tag,
java.lang.String param,
float default_value,
java.lang.String description)
Parses the array of string for a given option/parameter and returns a float value.
|
int |
getInteger(java.lang.String tag,
java.lang.String param,
int default_value,
java.lang.String description)
Parses the array of string for a given integer option/parameter.
|
long |
getLong(java.lang.String tag,
java.lang.String param,
long default_value,
java.lang.String description)
Parses the array of string for a given long option/parameter.
|
java.lang.String[] |
getRemainingStrings(boolean optional,
java.lang.String param,
java.lang.String description)
Gets the remaining parameters.
|
java.lang.String |
getString(java.lang.String tag,
java.lang.String param,
java.lang.String default_value,
java.lang.String description)
Parses the array of string for a given string option/parameter.
|
java.lang.String[] |
getStringTuple(java.lang.String tag,
int len,
java.lang.String param,
java.lang.String[] default_value,
java.lang.String description)
Parses the array of string for a given tuple option.
|
int |
size()
Gets the number of unparsed strings.
|
java.lang.String |
toString() |
java.lang.String |
toUsageString(java.lang.String program)
Gets the usage description.
|
public static final java.lang.String PARAM
public static final java.lang.String OPTIONAL_PARAM
public static boolean FIRST_PARAMS_THEN_OPTIONS
public static java.lang.String TAB1
public static java.lang.String TAB2
public static java.lang.String TAB3
public Flags(java.lang.String[] args)
args
- array of string contains the options and/or parameters.public boolean getBoolean(java.lang.String tag, java.lang.String description)
tag
- option tag (e.g. '-u' or '--help')description
- a description of this option/parameterpublic java.lang.Boolean getBoolean(java.lang.String tag, java.lang.Boolean default_value, java.lang.String description)
tag
- option tag (e.g. '-u' or '!-u')default_value
- default valuedescription
- a description of this option/parameterpublic java.lang.String getString(java.lang.String tag, java.lang.String param, java.lang.String default_value, java.lang.String description)
tag
- option tag (e.g. '-a' or '--add'); use PARAM
or OPTIONAL_PARAM
to indicate that iti is a parameter without tagparam
- parameter string used to represent the value in the help string;default_value
- default valuedescription
- a description of this option/parameter for the help string; if it is null, no description is added to the help stringpublic int getInteger(java.lang.String tag, java.lang.String param, int default_value, java.lang.String description)
tag
- option tag (e.g. '-a' or '--add'); use PARAM
or OPTIONAL_PARAM
to indicate that iti is a parameter without tagparam
- parameter string; if not null it is the string used to represent the parameter valuedefault_value
- default valuedescription
- a descriptionpublic long getLong(java.lang.String tag, java.lang.String param, long default_value, java.lang.String description)
tag
- option tag (e.g. '-a' or '--add'); use PARAM
or OPTIONAL_PARAM
to indicate that iti is a parameter without tagparam
- parameter string used to represent the value in the help string;default_value
- default valuedescription
- a description of this option/parameter for the help string; if it is null, no description is added to the help stringpublic float getFloat(java.lang.String tag, java.lang.String param, float default_value, java.lang.String description)
tag
- option tag (e.g. '-a' or '--add'); use PARAM
or OPTIONAL_PARAM
to indicate that iti is a parameter without tagparam
- parameter string used to represent the value in the help string;default_value
- default valuedescription
- a description of this option/parameter for the help string; if it is null, no description is added to the help stringpublic double getDouble(java.lang.String tag, java.lang.String param, double default_value, java.lang.String description)
tag
- option tag (e.g. '-a' or '--add'); use PARAM
or OPTIONAL_PARAM
to indicate that iti is a parameter without tagparam
- parameter string used to represent the value in the help stringdefault_value
- default valuedescription
- a description of this option/parameter for the help string; if it is null, no description is added to the help stringpublic java.lang.String[] getStringTuple(java.lang.String tag, int len, java.lang.String param, java.lang.String[] default_value, java.lang.String description)
tag
- option tag (e.g. '-v' or '--values')len
- the number of components of the tupleparam
- parameter string used to represent the value in the help stringdefault_value
- default valuedescription
- a description of this option for the help string; if it is null, no description is added to the help stringpublic java.lang.String[] getRemainingStrings(boolean optional, java.lang.String param, java.lang.String description)
optional
- whether these parameters are optionalparam
- string used to represent the parameter valuesdescription
- a description of these parameterspublic int size()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toUsageString(java.lang.String program)
program
- the main class