|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object info.rolandkrueger.roklib.cli.CommandLineArgumentEvaluator
public class CommandLineArgumentEvaluator
This class can be used to handle a program's command line options in an easy
and uncomplicated way. To use a CommandLineArgumentEvaluator
, you
first have to define the set of all available command line options and pass
them to the CommandLineArgumentEvaluator
with the
addOptions(CommandLineOption...)
or
addOptions(Collection)
methods. After
that, the evaluator object can be queried if the program was provided with
the correct options.
CommandLineOption
Nested Class Summary | |
---|---|
static class |
CommandLineArgumentEvaluator.UserInputValidity
Enum which is used to describe whether the arguments provided by the user via the command line were valid and if not so, what was wrong about them. |
Field Summary | |
---|---|
private boolean |
mAllowClusteredShortOptions
|
private boolean |
mAllowStandaloneValues
|
private String[] |
mArgs
|
private String |
mDescription
|
private CommandLineOption |
mErroneousOption
|
private boolean |
mEvaluated
|
private String |
mLongOptionsMarker
|
private Set<CommandLineOption> |
mMandatoryList
|
private List<CommandLineOption> |
mMutuallyExclusiveOptionsGiven
|
private Set<CommandLineOption> |
mOptionSet
|
private String |
mShortOptionsMarker
|
private List<String> |
mStandaloneValues
|
private CommandLineArgumentEvaluator.UserInputValidity |
mStatus
|
private String |
mUnrecognizedOption
|
Constructor Summary | |
---|---|
CommandLineArgumentEvaluator()
|
|
CommandLineArgumentEvaluator(String[] arguments)
Creates a new CommandLineArgumentEvaluator object that is supposed
to check the given command line options. |
Method Summary | |
---|---|
void |
addOptions(Collection<CommandLineOption> options)
Adds a list of CommandLineOption objects to the internal option
list of this evaluator |
void |
addOptions(CommandLineOption... options)
Adds one or more options to the internal list of all available options. |
void |
allowClusteredShortOptions(boolean yesNo)
|
void |
allowStandAloneValues(boolean yesNo)
|
private boolean |
disassembleFlagCluster(String value)
|
void |
evaluate()
After all available options have been configured and added to the evaluator object, the command line options given through the constructor are evaluated, such that after that it can be checked whether the user-provided options are correct or not. |
void |
evaluateAndInvokeCallbacks()
|
String |
getDescription()
|
String |
getDescriptiveSummaryFor(CommandLineOption option)
|
String |
getDescriptiveSummaryFor(CommandLineOption option,
String descriptionSeparator)
|
CommandLineOption |
getErroneousOption()
|
CommandLineArgumentEvaluator.UserInputValidity |
getInputStatus()
Returns the status of the command line options given by the user. |
String |
getLongOptionsMarker()
|
List<CommandLineOption> |
getMissingOptions()
If after having specified the set of available and mandatory options and having called evaluate() the user has
omitted one or more of the mandatory options, these missing options can be
queried as a list. |
List<CommandLineOption> |
getMutuallyExclusiveOptionsBeingUsed()
|
String |
getOptionDescription()
This method will assemble a string containing an overview of all available options together with a general blueprint of how to correctly use these options. |
private CommandLineOption |
getOptionFor(String value,
boolean valueContainsMarker)
|
Set<CommandLineOption> |
getOptions()
Returns the internal list of CommandLineOption objects. |
String |
getShortOptionsMarker()
|
List<String> |
getStandaloneValues()
|
String |
getUnrecognizedOption()
|
void |
invokeCallbacks()
|
boolean |
isValid()
|
void |
setArgumentList(String[] args)
|
void |
setDescription(String description)
|
private void |
setErroneousOption(CommandLineOption erroneous)
|
void |
setLongOptionsMarker(String longOptionsMarker)
|
void |
setShortOptionsMarker(String shortOptionsMarker)
|
private boolean |
setUnrecognizedOption(String option)
|
private List<String> |
splitAtEqualSign(String value)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private String mShortOptionsMarker
private String mLongOptionsMarker
private Set<CommandLineOption> mOptionSet
private Set<CommandLineOption> mMandatoryList
private String[] mArgs
private CommandLineArgumentEvaluator.UserInputValidity mStatus
private boolean mEvaluated
private boolean mAllowClusteredShortOptions
private boolean mAllowStandaloneValues
private String mDescription
private List<String> mStandaloneValues
private String mUnrecognizedOption
private CommandLineOption mErroneousOption
private List<CommandLineOption> mMutuallyExclusiveOptionsGiven
Constructor Detail |
---|
public CommandLineArgumentEvaluator()
public CommandLineArgumentEvaluator(String[] arguments)
CommandLineArgumentEvaluator
object that is supposed
to check the given command line options.
arguments
- the command line options for this application as optained by the
main()
method, for exampleMethod Detail |
---|
public void setArgumentList(String[] args)
public void addOptions(CommandLineOption... options)
options
- an option array which contains all necessary information of a
specific command line optionpublic void allowClusteredShortOptions(boolean yesNo)
public void allowStandAloneValues(boolean yesNo)
public List<String> getStandaloneValues()
public void addOptions(Collection<CommandLineOption> options)
CommandLineOption
objects to the internal option
list of this evaluator
options
- a collection of CommandLineOption
objectspublic Set<CommandLineOption> getOptions()
CommandLineOption
objects.
CommandLineOption
objects.public void evaluate()
IllegalStateException
- if this method was called more than onceprivate boolean setUnrecognizedOption(String option)
public String getUnrecognizedOption()
private void setErroneousOption(CommandLineOption erroneous)
public CommandLineOption getErroneousOption()
public String getDescriptiveSummaryFor(CommandLineOption option)
public String getDescriptiveSummaryFor(CommandLineOption option, String descriptionSeparator)
public List<CommandLineOption> getMutuallyExclusiveOptionsBeingUsed()
private boolean disassembleFlagCluster(String value)
private List<String> splitAtEqualSign(String value)
private CommandLineOption getOptionFor(String value, boolean valueContainsMarker)
public boolean isValid()
public void evaluateAndInvokeCallbacks()
public void invokeCallbacks()
public CommandLineArgumentEvaluator.UserInputValidity getInputStatus()
evaluate()
. Otherwise, a
IllegalStateException
will be thrown.
IllegalStateException
- if this method is called without invoking
evaluate()
beforehandCommandLineArgumentEvaluator.UserInputValidity
public String getOptionDescription()
CommandLineOption
object.
public List<CommandLineOption> getMissingOptions()
evaluate()
the user has
omitted one or more of the mandatory options, these missing options can be
queried as a list.
public String getShortOptionsMarker()
public void setShortOptionsMarker(String shortOptionsMarker)
public String getLongOptionsMarker()
public void setDescription(String description)
public String getDescription()
public void setLongOptionsMarker(String longOptionsMarker)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |