public class ArgsEngine extends Object
The following shows how to use this API.
// Initiate the arguments engine. ArgsEngine engine = new ArgsEngine(); // Configure the switches/options. Use true for valued options engine.add("-q", "--quiet"); engine.add("-o", "--redirect-output", true); engine.add("-h", "--help"); // Perform the parsing. engine.parse(args); // Start fetching states of switches boolean quiet = engine.getBoolean("-q"); if(engine.getBoolean("-o")) { // For valued options, use getString. String redir = engine.getString("-o"); }This has been modified from the original.
Constructor and Description |
---|
ArgsEngine() |
Modifier and Type | Method and Description |
---|---|
void |
add(String shortForm,
String longForm)
Configures the engine by adding options.
|
void |
add(String shortForm,
String longForm,
boolean valued)
Configures the engine by adding options.
|
boolean |
getBoolean(String key)
Gets the option.
|
String |
getString(String key)
Gets the value for a valued option.
|
void |
parse(String[] args)
Parses the input command line arguments.
|
public void add(String shortForm, String longForm)
shortForm
- the short form of an option. Example: "-h".longForm
- the long form of an option. Example: "--help".public void add(String shortForm, String longForm, boolean valued)
shortForm
- the short form of an option. Example: "-h".longForm
- the long form of an option. Example: "--help".valued
- indicates if the option expects a value. The next argument
will be considered as the value for this option.public void parse(String[] args)
Operations getBoolean(String)
, #getNonOptions()
and getString(String)
can be then used to extract the values.
args
- the command line arguments.public String getString(String key)
key
- the valued option key. Either short form or long form
can be input.public boolean getBoolean(String key)
key
- the option's short form or long form name.Copyright © 2019. All rights reserved.