Class StringOption
java.lang.Object
eu.svjatoslav.commons.cli_helper.parameter_parser.Option<String,StringOption>
eu.svjatoslav.commons.cli_helper.parameter_parser.parameter.StringOption
Represents a command-line option that accepts exactly one string parameter.
An optional default value can be provided; if so, this option is considered "present" even without user input.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal String
Default value to return if the user does not provide a parameter.Fields inherited from class eu.svjatoslav.commons.cli_helper.parameter_parser.Option
description, mandatory, parameters
-
Constructor Summary
ConstructorsConstructorDescriptionStringOption
(String description) Constructs a StringOption with no default value.StringOption
(String description, String defaultValue) Constructs a StringOption with a specified default value. -
Method Summary
Modifier and TypeMethodDescriptionDescribes the kind or format of the expected parameter(s), e.g.getValue()
Returns the string parameter or the default value if none was provided.boolean
Always returnstrue
since any string is considered valid for this option.Methods inherited from class eu.svjatoslav.commons.cli_helper.parameter_parser.Option
addAliases, addParameter, getAliasesAsString, getHelp, isMandatory, isPresent, matchesAlias, noMoreArguments, setMandatory, setPresent
-
Field Details
-
defaultValue
Default value to return if the user does not provide a parameter. If non-null, this option is automatically considered present.
-
-
Constructor Details
-
StringOption
Constructs a StringOption with no default value.- Parameters:
description
- a brief description of what this option does.
-
StringOption
Constructs a StringOption with a specified default value.- Parameters:
description
- a brief description of what this option does.defaultValue
- the default string to use if the user does not supply a parameter.
-
-
Method Details
-
describeFormat
Description copied from class:Option
Describes the kind or format of the expected parameter(s), e.g. "File", "Integer", etc.- Specified by:
describeFormat
in classOption<String,
StringOption> - Returns:
- a short string describing the parameter format
-
getValue
Returns the string parameter or the default value if none was provided.- Specified by:
getValue
in classOption<String,
StringOption> - Returns:
- the parsed value as the generic type T.
- Throws:
RuntimeException
- if multiple parameters were provided.
-
isValid
Always returnstrue
since any string is considered valid for this option.- Specified by:
isValid
in classOption<String,
StringOption> - Parameters:
value
- the parameter string to test- Returns:
true
if valid;false
otherwise
-