Package studio.mevera.imperat.context
Interface ExecutionContext<S extends CommandSource>
- Type Parameters:
S- the type of the command source/sender
- All Superinterfaces:
CommandContext<S>
@AvailableSince("1.0.0")
public interface ExecutionContext<S extends CommandSource>
extends CommandContext<S>
Represents the execution context for a command, responsible for resolving and managing
command arguments, flags, and their values during command execution.
This interface serves as the bridge between raw command input and executable command logic by:
- Resolving string inputs into typed values
- Managing command flags and their values
- Caching resolved arguments for execution
- Tracking the command execution path
Each Command maintains its own context, allowing subcommands to have
independent argument resolution while preserving the full execution chain.
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoiddebug()Debugs the current resolved arguments cached/mapped.
This requiresImperatDebuggerto be enabled.
Example:ImperatDebugger.setEnabled(true)<T> TgetArgument(String name) Gets a resolved command argument by its parameter name.default <T> TgetArgumentOr(String name, T value) Gets a resolved argument or returns a default value if not present.Gets all commands in the resolution path.<T> TgetContextArgument(Class<T> type) Gets an argument resolved by the context resolver system.Gets the command usage pattern that matched the input.Retrieves a flag by its name if it was provided in the command input.<T> TgetFlagValue(String flagName) Gets the resolved value of a command flag.Gets the most specific command that was resolved in this context.@Nullable ParsedArgument<S>getParsedArgument(String argumentName) @Nullable ParsedArgument<S>getParsedArgument(Command<S> command, String name) Gets a resolved argument by its owning command and parameter name.Collection<? extends ParsedArgument<S>>Gets all resolved arguments in input order.getParsedArguments(Command<S> command) Gets all resolved arguments for a specific command.default StringgetRawArgument(int index) Gets the raw string input for an argument by its position.Collection<? extends ParsedFlagArgument>Gets all flags that were resolved from the command input.@NotNull TreeExecutionResult<S>voidhandleRemainingParsing(TreeExecutionResult<S> result) default booleanhasResolvedFlag(Argument<S> currentParameter) Checks if a flag parameter was resolved in this context.booleanhasResolvedFlag(FlagData<S> flagData) Checks if a flag was resolved in this context.<T> voidparseArgument(Cursor<S> stream, T value) Resolves and registers a command argument.voidparseArgument(ParsedArgument<S> argument) Registers a resolved argument in the context.<R> RprovideSource(Type type) Resolves the command source into a different type using the configured source resolver.voidresolveFlag(ParsedFlagArgument<S> flag) Registers a resolved flag in the context.voidsetDetectedPathway(CommandPathway<S> pathway) voidsetTreeResult(TreeExecutionResult<S> treeResult) Methods inherited from interface studio.mevera.imperat.context.CommandContext
arguments, command, getRootCommandLabelUsed, imperat, imperatConfig, source
-
Method Details
-
getTreeExecutionResult
-
setDetectedPathway
-
handleRemainingParsing
- Throws:
CommandException
-
getFlag
Retrieves a flag by its name if it was provided in the command input.- Parameters:
flagName- the name of the flag (without prefix)- Returns:
- an
Optionalcontaining the flag if present, empty otherwise
-
getFlagValue
Gets the resolved value of a command flag.- Type Parameters:
T- the type of the flag value- Parameters:
flagName- the name of the flag (without prefix)- Returns:
- the resolved flag value, or
nullif:- The flag is a switch (no value)
- The flag wasn't provided
- The value couldn't be resolved
-
getArgument
Gets a resolved command argument by its parameter name.- Type Parameters:
T- the type of the argument value- Parameters:
name- the parameter name defined in theCommandPathway- Returns:
- the resolved argument value, or
nullif not provided or couldn't be resolved - See Also:
-
getArgumentOr
Gets a resolved argument or returns a default value if not present.- Type Parameters:
T- the type of the argument value- Parameters:
name- the parameter namevalue- the default value to return if argument isn't present- Returns:
- the resolved argument value or the default value
-
getRawArgument
Gets the raw string input for an argument by its position.- Parameters:
index- the zero-based position of the argument in the command input- Returns:
- the raw argument string, or
nullif index is out of bounds
-
provideSource
Resolves the command source into a different type using the configured source resolver.- Type Parameters:
R- the target type to resolve to- Parameters:
type- the target type class- Returns:
- the resolved source, never
null - Throws:
CommandException- if resolution fails- See Also:
-
getContextArgument
Gets an argument resolved by the context resolver system.- Type Parameters:
T- the type of the argument- Parameters:
type- the class of the argument type- Returns:
- the resolved argument value, or
nullif not resolvable - Throws:
CommandException- if resolution fails- See Also:
-
getResolvedFlags
Collection<? extends ParsedFlagArgument> getResolvedFlags()Gets all flags that were resolved from the command input.- Returns:
- a collection of resolved flags
-
parseArgument
Resolves and registers a command argument.- Type Parameters:
T- the type of the argument value- Parameters:
stream- the stream having the current input's data.value- the resolved value.- Throws:
CommandException- if resolution fails.
-
parseArgument
Registers a resolved argument in the context.- Parameters:
argument- the resolved argument to register- Throws:
CommandException
-
resolveFlag
Registers a resolved flag in the context.- Parameters:
flag- the resolved flag to register- Throws:
CommandException
-
getLastUsedCommand
Gets the most specific command that was resolved in this context.- Returns:
- the terminal command that will be executed
-
getDetectedPathway
CommandPathway<S> getDetectedPathway()Gets the command usage pattern that matched the input.- Returns:
- the detected command usage
-
getParsedArgument
Gets a resolved argument by its owning command and parameter name.- Parameters:
command- the owning commandname- the parameter name- Returns:
- the resolved argument, or
nullif not present
-
getParsedArgument
-
getParsedArguments
Gets all resolved arguments for a specific command.- Parameters:
command- the owning command- Returns:
- a list of resolved arguments in declaration order
-
getCommandsUsed
Gets all commands in the resolution path.- Returns:
- an iterable of all commands from root to terminal command
-
getParsedArguments
Collection<? extends ParsedArgument<S>> getParsedArguments()Gets all resolved arguments in input order.- Returns:
- a collection of arguments in the order they appeared in the input
-
hasResolvedFlag
Checks if a flag parameter was resolved in this context.- Parameters:
currentParameter- the flag parameter to check- Returns:
trueif the flag was provided and resolved
-
hasResolvedFlag
Checks if a flag was resolved in this context.- Parameters:
flagData- the flag definition to check- Returns:
trueif the flag was provided and resolved
-
debug
void debug()Debugs the current resolved arguments cached/mapped.
This requiresImperatDebuggerto be enabled.
Example:ImperatDebugger.setEnabled(true) -
setTreeResult
-