public interface Switch extends SwitchOrArgument
A switch can appear in a short one-character form
like -k
or a long form like --kill-all-idiots
.
Long forms can have an argument directly append separated by
an equals sign (=
), or as next command line argument.
Short forms only accept the latter.
Modifier and Type | Method and Description |
---|---|
default boolean |
consumeArgument(java.lang.String arg)
Read further arguments from the command line.
|
void |
found(char shortSwitch)
This switch appears in the command line in the given short form.
|
void |
found(java.lang.String longSwitch)
This switch appears in the command line in the given long form.
|
java.util.Collection<java.lang.String> |
getLongForms()
Get the long forms influencing this switch.
|
java.util.Collection<java.lang.Character> |
getShortForms()
Get the short one character forms influencing this switch.
|
default boolean |
isOptional()
Is this an optional switch?
|
default boolean |
isSwitch()
Is this a switch?
|
default boolean |
needsArguments()
Does this switch require arguments?
|
getAppearance, getDescription
default boolean isSwitch()
SwitchOrArgument
isSwitch
in interface SwitchOrArgument
true
: this is a switch and can be casted to Switch
,
false
: this is a argument and can be casted to Argument
@NotNull java.util.Collection<java.lang.Character> getShortForms()
If the command line switch is -k
, this method
should return a singleton collection with the character
k
.
@NotNull java.util.Collection<java.lang.String> getLongForms()
The return strings must not include the --
prefix,
and have to consist of characters, digits and the minus
sign (-
.
So if the command line switch is --kill-all-idiots
,
this method should return a singleton collection with the
string kill-all-idiots
.
default boolean isOptional()
true
.isOptional
in interface SwitchOrArgument
true
: if this switch is optionalfalse
: if this switch is requiredvoid found(char shortSwitch)
shortSwitch
- short form in which this switch appearedvoid found(@NotNull java.lang.String longSwitch)
longSwitch
- long formdefault boolean needsArguments()
consumeArgument(String)
method will be called.
The default implementation returns false
, so always both
this method and the consumeArgument(String)
method need to
be overridden.true
if this switch requires argumentsfalse
if this switch does not require argumentsconsumeArgument(String)
default boolean consumeArgument(@NotNull java.lang.String arg)
consumeArgument
in interface SwitchOrArgument
arg
- argumentneedsArguments()