Package com.martiansoftware.jsap
Class UnflaggedOption
- java.lang.Object
-
- com.martiansoftware.jsap.Parameter
-
- com.martiansoftware.jsap.Option
-
- com.martiansoftware.jsap.UnflaggedOption
-
public final class UnflaggedOption extends Option
An option whose meaning is derived from its position in the argument list rather than a flag that precedes it. UnflaggedOptions allow the parsing of command lines without flags, such as "compressfiles destinationFile file1 file2 file3 file4 ...", where "destinationFile" is the name of the file to create, and file1 through file 4 (and beyond) are the names of the files to compress. The JSAP that supports this command line has only two options defined: the first accepts a single destination file, and the second is "greedy," consuming the remaining unflagged options.- Author:
- Marty Lamb
- See Also:
FlaggedOption
,Option
-
-
Constructor Summary
Constructors Constructor Description UnflaggedOption(java.lang.String id)
Creates a new UnflaggedOption with the specified unique ID.UnflaggedOption(java.lang.String id, StringParser stringParser, boolean required, java.lang.String help)
A shortcut constructor that creates a new non-greedy UnflaggedOption with no default value and configures its most commonly used settings.UnflaggedOption(java.lang.String id, StringParser stringParser, java.lang.String defaultValue, boolean required, boolean greedy)
A shortcut constructor that creates a new UnflaggedOption and configures its most commonly used settings.UnflaggedOption(java.lang.String id, StringParser stringParser, java.lang.String defaultValue, boolean required, boolean greedy, java.lang.String help)
A shortcut constructor that creates a new UnflaggedOption and configures its most commonly used settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getSyntax()
Returns syntax instructions for this FlaggedOption.boolean
isGreedy()
Returns a boolean indicating whether this UnflaggedOption is greedy.UnflaggedOption
setDefault(java.lang.String defaultValue)
Sets a default value for this parameter.UnflaggedOption
setDefault(java.lang.String[] defaultValues)
Sets one or more default values for this parameter.UnflaggedOption
setGreedy(boolean greedy)
Sets whether this UnflaggedOption is greedy.UnflaggedOption
setList(boolean isList)
Sets whether this UnflaggedOption is a list.UnflaggedOption
setListSeparator(char listSeparator)
Sets the list separator character for this UnflaggedOption.UnflaggedOption
setRequired(boolean required)
Sets whether this UnflaggedOption is required.UnflaggedOption
setStringParser(StringParser stringParser)
Sets the StringParser to which this UnflaggedOption's parse() method should delegate.UnflaggedOption
setUsageName(java.lang.String usageName)
Sets the name that will be displayed when getUsage() is called-
Methods 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 Detail
-
UnflaggedOption
public UnflaggedOption(java.lang.String id)
Creates a new UnflaggedOption with the specified unique ID.- Parameters:
id
- the unique ID for this UnflaggedOption.
-
UnflaggedOption
public UnflaggedOption(java.lang.String id, StringParser stringParser, java.lang.String defaultValue, boolean required, boolean greedy, java.lang.String help)
A shortcut constructor that creates a new UnflaggedOption and configures its most commonly used settings.- Parameters:
id
- the unique ID for this UnflaggedOptionstringParser
- the StringParser this UnflaggedOption should use.defaultValue
- the default value for this UnflaggedOption (may be null).required
- if true, this UnflaggedOption is required.greedy
- if true, this UnflaggedOption is greedy.help
- the help text for this option (may be set toJSAP.NO_HELP
for none).
-
UnflaggedOption
public UnflaggedOption(java.lang.String id, StringParser stringParser, java.lang.String defaultValue, boolean required, boolean greedy)
A shortcut constructor that creates a new UnflaggedOption and configures its most commonly used settings.- Parameters:
id
- the unique ID for this UnflaggedOptionstringParser
- the StringParser this UnflaggedOption should use.defaultValue
- the default value for this UnflaggedOption (may be null).required
- if true, this UnflaggedOption is required.greedy
- if true, this UnflaggedOption is greedy.
-
UnflaggedOption
public UnflaggedOption(java.lang.String id, StringParser stringParser, boolean required, java.lang.String help)
A shortcut constructor that creates a new non-greedy UnflaggedOption with no default value and configures its most commonly used settings.- Parameters:
id
- the unique ID for this UnflaggedOptionstringParser
- the StringParser this UnflaggedOption should use.required
- if true, this UnflaggedOption is required.help
- the help text for this option (may be set toJSAP.NO_HELP
for none).
-
-
Method Detail
-
setGreedy
public UnflaggedOption setGreedy(boolean greedy)
Sets whether this UnflaggedOption is greedy. A greedy UnflaggedOption consumes all the remaining UnflaggedOptions from the argument list. As a result, only one greedy UnflaggedOption may be registered with a JSAP, and it must be the last UnflaggedOption registered.- Parameters:
greedy
- if true, this UnflaggedOption will be greedy.- Returns:
- the modified UnflaggedOption
-
setUsageName
public UnflaggedOption setUsageName(java.lang.String usageName)
Sets the name that will be displayed when getUsage() is called- Parameters:
usageName
- the name to use, or null if the id should be used (default)- Returns:
- the modified UnflaggedOption
-
isGreedy
public boolean isGreedy()
Returns a boolean indicating whether this UnflaggedOption is greedy.- Returns:
- a boolean indicating whether this UnflaggedOption is greedy.
-
getSyntax
public java.lang.String getSyntax()
Returns syntax instructions for this FlaggedOption.
-
setList
public UnflaggedOption setList(boolean isList)
Sets whether this UnflaggedOption is a list. Default behavior is JSAP.NOT_LIST.- Parameters:
isList
- if true, this Option is a list.- Returns:
- the modified UnflaggedOption
-
setListSeparator
public UnflaggedOption setListSeparator(char listSeparator)
Sets the list separator character for this UnflaggedOption. The default list separator is JSAP.DEFAULT_LISTSEPARATOR.- Parameters:
listSeparator
- the list separator for this Option.- Returns:
- the modified UnflaggedOption
-
setRequired
public UnflaggedOption setRequired(boolean required)
Sets whether this UnflaggedOption is required. Default is JSAP.NOT_REQUIRED.- Parameters:
required
- if true, this Option will be required.- Returns:
- the modified UnflaggedOption
-
setStringParser
public UnflaggedOption setStringParser(StringParser stringParser)
Sets the StringParser to which this UnflaggedOption's parse() method should delegate.- Parameters:
stringParser
- the StringParser to which this Option's parse() method should delegate.- Returns:
- the modified UnflaggedOption
- See Also:
StringParser
-
setDefault
public UnflaggedOption setDefault(java.lang.String defaultValue)
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:
setDefault(String)
-
setDefault
public UnflaggedOption setDefault(java.lang.String[] defaultValues)
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(String)
-
-