|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.plt.text.ArgumentParser
public class ArgumentParser
A simple utility class for processing command-line argument arrays. Argument strings
are assumed to be made up of options, option arguments, and
parameters. All argument string beginning with the character '-' are
interpreted as options. Clients should specify the names and arities (and, optionally,
default values) of their supported options. Aliases may also be specified, allowing
multiple names to be interpreted as the same option. parse(java.lang.String...) may then be invoked on
an argument array, producing errors for unrecognized options or options with the wrong
number of arguments, and interpreting all remaining strings as parameters.
| Nested Class Summary | |
|---|---|
static class |
ArgumentParser.Result
A collection of the options and parameters parsed from an array of arguments. |
| Constructor Summary | |
|---|---|
ArgumentParser()
Create an argument parser with an initially-empty set of supported options. |
|
| Method Summary | |
|---|---|
ArgumentParser.Result |
parse(java.lang.String... args)
Parse an array of arguments based on the previously-defined supported options. |
void |
requireParams(int count)
Require at least the given number of parameters (0 by default). |
void |
requireStrictOrder()
Require all options to precede any parameters (not required by default). |
void |
supportAlias(java.lang.String aliasName,
java.lang.String optionName)
Create an alias: aliasName is an alias for optionName. |
void |
supportOption(java.lang.String name,
int arity)
Add the given option name to the list of supported options. |
void |
supportOption(java.lang.String name,
java.lang.String... defaultArguments)
Add the given option name to the list of supported options and record the given default argument set. |
boolean |
supportsOption(java.lang.String name)
Determine whether the given option is supported. |
void |
supportVarargOption(java.lang.String name)
Add the given option name to the list of supported options. |
void |
supportVarargOption(java.lang.String name,
java.lang.String... defaultArguments)
Add the given option name to the list of supported options and record the given default argument set. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ArgumentParser()
| Method Detail |
|---|
public void requireStrictOrder()
public void requireParams(int count)
public boolean supportsOption(java.lang.String name)
public void supportOption(java.lang.String name,
int arity)
name - The option name, excluding the "-" prefix.arity - The number of arguments to follow the option.
java.lang.IllegalArgumentException - If the option is already supported.
public void supportOption(java.lang.String name,
java.lang.String... defaultArguments)
name - The option name, excluding the "-" prefix.defaultArguments - The default arguments associated with the option. Implicitly defines the arity
of the option as well. If the length is 0, no default will be set (otherwise,
the nullary option would always appear to be present).
java.lang.IllegalArgumentException - If the option is already supported.public void supportVarargOption(java.lang.String name)
name - The option name, excluding the "-" prefix.
java.lang.IllegalArgumentException - If the option is already supported.
public void supportVarargOption(java.lang.String name,
java.lang.String... defaultArguments)
supportVarargOption(String) will be invoked instead.)
name - The option name, excluding the "-" prefix.defaultArguments - The default arguments associated with the option.
java.lang.IllegalArgumentException - If the option is already supported.
public void supportAlias(java.lang.String aliasName,
java.lang.String optionName)
aliasName is an alias for optionName. Parsed matches will appear
under the referenced option name in the result.
java.lang.IllegalArgumentException - If the alias name is already supported, or if the option name is
not supported.
public ArgumentParser.Result parse(java.lang.String... args)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||