public final class CommandInput
extends java.lang.Object
This should be initialized with the whole input string, e.g.:
/mycommand -b param1 -f flagValue param2
While this class technically supports null commands, that should only be used in special circumstances, such as when tokenizing for sub-command suggestions.
| Constructor and Description |
|---|
CommandInput(@NotNull Blade blade,
@Nullable BladeCommand command,
@NotNull java.lang.String input) |
CommandInput(@NotNull Blade blade,
@Nullable BladeCommand command,
@NotNull java.lang.String input,
@NotNull java.util.EnumSet<InputOption> options) |
CommandInput(@NotNull Blade blade,
@Nullable BladeCommand command,
@NotNull java.lang.String input,
InputOption... options) |
| Modifier and Type | Method and Description |
|---|---|
@NotNull java.util.List<ArgumentToken> |
arguments()
Get all argument tokens.
|
@Nullable BladeCommand |
bladeCommand()
Get the associated BladeCommand.
|
boolean |
endsInWhitespace()
Check if the input string ended with whitespace.
|
void |
ensureTokenized()
Ensure that the input has been tokenized.
|
@NotNull java.util.List<FlagToken> |
flags()
Get all flag tokens.
|
@NotNull java.lang.String |
input()
Get the original input string.
|
@NotNull java.util.Optional<LabelToken> |
label()
Get the label token, if present.
|
boolean |
mergeTokensToFormWholeLabel(@NotNull java.lang.String wholeLabel)
Merge tokens to form the given whole label.
|
<T extends Token> |
ofType(@NotNull java.lang.Class<T> tokenClass)
Get a stream of tokens of the specified type.
|
@NotNull java.util.EnumSet<InputOption> |
options()
Get the input options used during tokenization.
|
void |
tokenize()
Tokenize the input command string.
|
@NotNull @Unmodifiable java.util.List<Token> |
tokens()
Get the list of tokens produced by tokenization.
|
java.lang.String |
toString() |
@NotNull java.lang.String |
unslashedInput()
Get the original input string without a leading slash.
|
public CommandInput(@NotNull
@NotNull Blade blade,
@Nullable
@Nullable BladeCommand command,
@NotNull
@NotNull java.lang.String input)
public CommandInput(@NotNull
@NotNull Blade blade,
@Nullable
@Nullable BladeCommand command,
@NotNull
@NotNull java.lang.String input,
@NotNull
InputOption... options)
public CommandInput(@NotNull
@NotNull Blade blade,
@Nullable
@Nullable BladeCommand command,
@NotNull
@NotNull java.lang.String input,
@NotNull
@NotNull java.util.EnumSet<InputOption> options)
@NotNull public @NotNull java.lang.String unslashedInput()
@NotNull public @NotNull java.lang.String input()
@Nullable public @Nullable BladeCommand bladeCommand()
@NotNull public @NotNull java.util.EnumSet<InputOption> options()
@NotNull public @NotNull @Unmodifiable java.util.List<Token> tokens()
public boolean endsInWhitespace()
@NotNull public @NotNull java.util.Optional<LabelToken> label()
@NotNull public @NotNull java.util.List<ArgumentToken> arguments()
@NotNull public @NotNull java.util.List<FlagToken> flags()
@NotNull public <T extends Token> @NotNull java.util.stream.Stream<T> ofType(@NotNull @NotNull java.lang.Class<T> tokenClass)
T - the type of the tokentokenClass - the class of the token type to filter bypublic void ensureTokenized()
throws TokenizerError
TokenizerError - if a tokenization error occurspublic void tokenize()
throws TokenizerError
TokenizerError - if a tokenization error occurspublic boolean mergeTokensToFormWholeLabel(@NotNull
@NotNull java.lang.String wholeLabel)
This means that parameter tokens after the label will be deleted, and merged according to the given whole label.
For example:
- Tokens: [label: "my", arg: "command", arg: "param1"]
- Whole label: "my command"
- Resulting tokens: [label: "my command", arg: "param1"]
wholeLabel - the whole labelpublic java.lang.String toString()
toString in class java.lang.Object