Package com.martiansoftware.jsap
Class FlaggedOption
java.lang.Object
com.martiansoftware.jsap.Parameter
com.martiansoftware.jsap.Option
com.martiansoftware.jsap.FlaggedOption
- All Implemented Interfaces:
Flagged
- Direct Known Subclasses:
QualifiedSwitch
An option that implements the Flagged interface. A flagged option is
preceded by a short flag or a long flag; i.e. "-n 5" or "--number 5".
FlaggedOptions also provide an additional features over unflagged
options, namely the ability to be declared more than once in a command line
(e.g., "-n 5 -n 10"). This is not possible with unflagged options, as they
are never declared.
- Author:
- Marty Lamb
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionFlaggedOption
(String id) Creates a new FlaggedOption with the specified unique ID.FlaggedOption
(String id, StringParser stringParser, String defaultValue, boolean required, char shortFlag, String longFlag) A shortcut constructor that creates a new FlaggedOption and configures its most commonly used settings.FlaggedOption
(String id, StringParser stringParser, String defaultValue, boolean required, char shortFlag, String longFlag, String help) A shortcut constructor that creates a new FlaggedOption and configures its most commonly used settings, including help. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns a boolean indicating whether multiple declarations are allowed for this FlaggedOption.Returns the long flag for this FlaggedOption.char
Returns the short flag for this FlaggedOption.Returns the short flag for this FlaggedOption.Returns syntax instructions for this FlaggedOption.setAllowMultipleDeclarations
(boolean allowMultipleDeclarations) Sets this FlaggedOption to allow or disallow multiple declarations.setDefault
(String defaultValue) Sets a default value for this parameter.setDefault
(String[] defaultValues) Sets one or more default values for this parameter.setList
(boolean isList) Sets whether this FlaggedOption is a list.setListSeparator
(char listSeparator) Sets the list separator character for this FlaggedOption.setLongFlag
(String longFlag) Sets the long flag for this FlaggedOption.setRequired
(boolean required) Sets whether this FlaggedOption is required.setShortFlag
(char shortFlag) Sets the short flag for this FlaggedOption.setStringParser
(StringParser stringParser) Sets the StringParser to which this FlaggedOption's parse() method should delegate.setUsageName
(String usageName) Sets the name that will be displayed when getSyntax() is calledMethods inherited from class com.martiansoftware.jsap.Option
getListSeparator, getStringParser, internalSetList, internalSetListSeparator, internalSetRequired, internalSetStringParser, isList, parse, register, required, unregister
Methods inherited from class com.martiansoftware.jsap.Parameter
_setDefault, _setDefault, _setUsageName, addDefault, enforceParameterLock, getDefault, getHelp, getID, getUsage, getUsageName, locked, setHelp, setLocked
-
Constructor Details
-
FlaggedOption
Creates a new FlaggedOption with the specified unique ID.- Parameters:
id
- the unique ID for this FlaggedOption.
-
FlaggedOption
public FlaggedOption(String id, StringParser stringParser, String defaultValue, boolean required, char shortFlag, String longFlag, String help) A shortcut constructor that creates a new FlaggedOption and configures its most commonly used settings, including help.- Parameters:
id
- the unique ID for this FlaggedOption.stringParser
- the StringParser this FlaggedOption should use.defaultValue
- the default value for this FlaggedOption (may be null).required
- if true, this FlaggedOption is required.shortFlag
- the short flag for this option (may be set to JSAP.NO_SHORTFLAG for none).longFlag
- the long flag for this option (may be set to JSAP.NO_LONGFLAG for none).help
- the help text for this option (may be set toJSAP.NO_HELP
for none).
-
FlaggedOption
public FlaggedOption(String id, StringParser stringParser, String defaultValue, boolean required, char shortFlag, String longFlag) A shortcut constructor that creates a new FlaggedOption and configures its most commonly used settings.- Parameters:
id
- the unique ID for this FlaggedOption.stringParser
- the StringParser this FlaggedOption should use.defaultValue
- the default value for this FlaggedOption (may be null).required
- if true, this FlaggedOption is required.shortFlag
- the short flag for this option (may be set to JSAP.NO_SHORTFLAG for none).longFlag
- the long flag for this option (may be set to JSAP.NO_LONGFLAG for none).
-
-
Method Details
-
setShortFlag
Sets the short flag for this FlaggedOption. To use no short flag at all, set the value to JSAP.NO_SHORTFLAG.- Parameters:
shortFlag
- the short flag for this FlaggedOption.- Returns:
- the modified FlaggedOption
-
getShortFlag
public char getShortFlag()Returns the short flag for this FlaggedOption. If this FlaggedOption has no short flag, the return value will be equal to JSAP.NO_SHORTFLAG.- Specified by:
getShortFlag
in interfaceFlagged
- Returns:
- the short flag for this FlaggedOption. If this FlaggedOption has no short flag, the return value will be equal to JSAP.NO_SHORTFLAG.
-
getShortFlagCharacter
Returns the short flag for this FlaggedOption. If this FlaggedOption has no short flag, the return value will be null.- Specified by:
getShortFlagCharacter
in interfaceFlagged
- Returns:
- the short flag for this FlaggedOption. If this FlaggedOption has no short flag, the return value will be null.
-
setLongFlag
Sets the long flag for this FlaggedOption. To use no long flag at all, set the value to JSAP.NO_LONGFLAG.- Parameters:
longFlag
- the long flag for this FlaggedOption.- Returns:
- the modified FlaggedOption
-
setUsageName
Sets the name that will be displayed when getSyntax() is called- Parameters:
usageName
- the name to use, or null if the id should be used (default)- Returns:
- the modified FlaggedOption
-
getLongFlag
Returns the long flag for this FlaggedOption. If this FlaggedOption has no long flag, the return value will be equal to JSAP.NO_LONGFLAG.- Specified by:
getLongFlag
in interfaceFlagged
- Returns:
- the long flag for this FlaggedOption. If this FlaggedOption has no long flag, the return value will be equal to JSAP.NO_LONGFLAG.
-
setAllowMultipleDeclarations
Sets this FlaggedOption to allow or disallow multiple declarations. If multiple declarations are allowed, the flag may be specified multiple times on the command line (e.g., "-n 5 -n 10"). All of the results are aggregated in the resulting JSAPResult.
Default behavior is to disallow multiple declarations.
- Parameters:
allowMultipleDeclarations
- if true, multiple declarations are allowed.- Returns:
- the modified FlaggedOption
-
allowMultipleDeclarations
public boolean allowMultipleDeclarations()Returns a boolean indicating whether multiple declarations are allowed for this FlaggedOption.- Returns:
- a boolean indicating whether multiple declarations are allowed for this FlaggedOption.
- See Also:
-
getSyntax
Returns syntax instructions for this FlaggedOption. -
setList
Sets whether this FlaggedOption is a list. Default behavior is JSAP.NOT_LIST.- Parameters:
isList
- if true, this Option is a list.- Returns:
- the modified FlaggedOption
-
setListSeparator
Sets the list separator character for this FlaggedOption. The default list separator is JSAP.DEFAULT_LISTSEPARATOR.- Parameters:
listSeparator
- the list separator for this Option.- Returns:
- the modified FlaggedOption
-
setRequired
Sets whether this FlaggedOption is required. Default is JSAP.NOT_REQUIRED.- Parameters:
required
- if true, this Option will be required.- Returns:
- the modified FlaggedOption
-
setDefault
Sets one or more default values for this parameter. This method should be used whenever a parameter has more than one default value.- Parameters:
defaultValues
- the default values for this parameter.- See Also:
-
setDefault
Sets a default value for this parameter. The default is specified as a String, and is parsed as a single value specified on the command line. In other words, default values for "list" parameters or parameters allowing multiple declarations should be set using setDefault(String[]), as JSAP would otherwise treat the entire list of values as a single value.- Parameters:
defaultValue
- the default value for this parameter.- See Also:
-
setStringParser
Sets the StringParser to which this FlaggedOption's parse() method should delegate.- Parameters:
stringParser
- the StringParser to which this Option's parse() method should delegate.- Returns:
- the modified FlaggedOption
- See Also:
-