Class Option<T,I extends Option>
java.lang.Object
eu.svjatoslav.commons.cli_helper.parameter_parser.Option<T,I>
- Type Parameters:
T
- type of value that this option returns.I
- type of this option.
- Direct Known Subclasses:
DirectoryOption
,DirectoryOptions
,FileOption
,FileOptions
,FloatOption
,IntegerOption
,NullOption
,StringOption
,StringOptions
Represents an option that can be provided on CLI.
This class allows specifying whether the option is mandatory,
the parameter count, a description, and any aliases for the option.
-
Field Summary
Modifier and TypeFieldDescriptionfinal String
Purpose of this option, like: input image path, compression level, etc...protected boolean
Indicates that at least one parameter is mandatory for this option.List of arguments for this parameter. -
Constructor Summary
ConstructorDescriptionOption
(boolean mandatory, ParameterCount parameterCount, String description, String... aliases2) Represents an option that can be provided on CLI.Option
(String description, ParameterCount parameterCount) -
Method Summary
Modifier and TypeMethodDescriptionaddAliases
(String... aliasArray) Adds additional aliases to the option.boolean
addParameter
(String parameterString) abstract String
getHelp()
Returns the help message for this parameter.abstract T
getValue()
Returns the value of the object.boolean
boolean
abstract boolean
boolean
matchesAlias
(String alias) boolean
Notifies this option that no more parameters will follow.Sets the option as mandatory.protected void
setPresent
(boolean present) Sets the present status of this parameter.
-
Field Details
-
description
Purpose of this option, like: input image path, compression level, etc... Note: for describing option type there isdescribeFormat()
. -
parameters
List of arguments for this parameter. -
mandatory
protected boolean mandatoryIndicates that at least one parameter is mandatory for this option.
-
-
Constructor Details
-
Option
public Option(boolean mandatory, ParameterCount parameterCount, String description, String... aliases2) Represents an option that can be provided on CLI. This class allows specifying whether the option is mandatory, the parameter count, a description, and any aliases for the option.- Parameters:
mandatory
- indicates whether the option is mandatoryparameterCount
- the number of parameters required for the optiondescription
- a description of the optionaliases2
- any additional aliases for the option
-
Option
-
-
Method Details
-
addAliases
Adds additional aliases to the option.- Parameters:
aliasArray
- an array of strings representing the aliases to be added- Returns:
- the modified option object
-
addParameter
- Parameters:
parameterString
- parameter to add- Returns:
true
if no errors were found.false
otherwise.
-
describeFormat
- Returns:
- Single line parameter type description. For example: "file", "date", "integer", "regular expression", etc..
Note: for argument purpose description there is
description
-
getAliasesAsString
- Returns:
- aliases for this parameter as string.
-
getHelp
Returns the help message for this parameter.- Returns:
- the help message as a string.
-
getValue
Returns the value of the object.- Returns:
- the value of the object.
-
isMandatory
public boolean isMandatory() -
isPresent
public boolean isPresent()- Returns:
true
if this parameter was present in the commandline.
-
setPresent
protected void setPresent(boolean present) Sets the present status of this parameter.- Parameters:
present
-true
if this parameter is present in the command line,false
otherwise.
-
matchesAlias
- Parameters:
alias
- alias to check against- Returns:
true
if given alias is registered for this parameter.
-
noMoreArguments
public boolean noMoreArguments()Notifies this option that no more parameters will follow. This gives option chance to verify if this is ok.- Returns:
true
if no errors were found.false
otherwise.
-
setMandatory
Sets the option as mandatory. This means that the option must be provided by the user in order for the program to run successfully.- Returns:
- The updated instance of the option.
-
isValid
- Parameters:
value
- value to validate- Returns:
true
if value is correct,false
otherwise.
-