Package com.github.hypfvieh.cli.parser
Class CmdArgOption<T>
java.lang.Object
com.github.hypfvieh.cli.parser.CmdArgOption<T>
Describes a command-line option.
Options are created using the associated
Options are created using the associated
CmdArgOption.Builder.
Sample Usage:
{@code
CmdArgOption<ITransformer> optImpl = CmdArgOption.builder(ITransformer.class)
.name("transformerClass")
.description("FQCN of transformer implementation")
.required(true)
.build();
CommandLine cli = new CommandLine().addOptions(optImpl);
// ...
cli.parse(args);
if (cli.hasOption(optImpl)) {
ITransformer transformer = cli.getArg(optImpl);
// ...
}
</pre>
@param <T> data type of the option
@author David M.
@author Markus S.
@since 1.0.0 - 2022-04-19-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for a command-line option.
The builder guarantees the option it builds is valid.
At a minimum an option requires a name. -
Method Summary
Modifier and TypeMethodDescriptionstatic CmdArgOption.Builder<Void>builder()Returns a builder for a new option without value (therefore default value not permitted).static <T> CmdArgOption.Builder<T>Returns a builder for a new option with the specified data type.
As the data type is specified, the option must have a value (and may have a default value).booleanClass<?>Returns the type of data to create from argument.Returns the default value for this option (when option was not set).Returns the description text for this option.getName()Returns the long name of this optionReturns the short name of this option.inthashCode()booleanhasValue()Flag to signal if the option requires a value.booleanFlag to signal that this option is optional.booleanFlag to allow the option to be repeated multiple times.booleanFlag to signal if this option is required.toString()
-
Method Details
-
getName
Returns the long name of this option- Returns:
- String, maybe null or empty
-
getShortName
Returns the short name of this option.- Returns:
- String, maybe empty or null
-
getDescription
Returns the description text for this option.- Returns:
- String, maybe empty or null
-
isRequired
public boolean isRequired()Flag to signal if this option is required.- Returns:
- true if required
-
isRepeatable
public boolean isRepeatable()Flag to allow the option to be repeated multiple times.- Returns:
- true if repeatable
-
isOptional
public boolean isOptional()Flag to signal that this option is optional.- Returns:
- true if optional
-
hasValue
public boolean hasValue()Flag to signal if the option requires a value.- Returns:
- true if value required
-
getDefaultValue
Returns the default value for this option (when option was not set).- Returns:
- default value, maybe null
-
getDataType
Returns the type of data to create from argument.- Returns:
- class, maybe null
-
hashCode
public int hashCode() -
equals
-
toString
-
builder
Returns a builder for a new option with the specified data type.
As the data type is specified, the option must have a value (and may have a default value).- Type Parameters:
T- data type of the option- Parameters:
_dataType- data type of option- Returns:
- builder
-
builder
Returns a builder for a new option without value (therefore default value not permitted).- Returns:
- builder
-