Package studio.mevera.imperat.context
Interface ExecutionContext<S extends Source>
- Type Parameters:
S- the type of the command source/sender
- All Superinterfaces:
Context<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> TgetContextResolvedArgument(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.@NotNull CommandPathSearch<S>Fetches the command path search instance used to resolve the command execution path.default StringgetRawArgument(int index) Gets the raw string input for an argument by its position.getResolvedArgument(Command<S> command, String name) Gets a resolved argument by its owning command and parameter name.Collection<? extends Argument<S>>Gets all resolved arguments in input order.getResolvedArguments(Command<S> command) Gets all resolved arguments for a specific command.Collection<? extends ExtractedInputFlag>Gets all flags that were resolved from the command input.<R> RgetResolvedSource(Type type) Resolves the command source into a different type using the configured source resolver.default booleanhasResolvedFlag(CommandParameter<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.voidresolve()Resolves all arguments and flags from the raw context input.<T> voidresolveArgument(Command<S> command, @Nullable String raw, int index, CommandParameter<S> parameter, T value) Resolves and registers a command argument.default <T> voidresolveArgument(CommandInputStream<S> stream, T value) Resolves and registers a command argument.default voidresolveFlag(FlagData<S> flagDetected, String flagRaw, @Nullable String flagInputRaw, @Nullable Object flagInputValue) Resolves a command flag from its raw components.voidRegisters a resolved flag in the context.
-
Method Details
-
getPathwaySearch
Fetches the command path search instance used to resolve the command execution path. This provides access to the full command hierarchy leading to the executed command.- Returns:
- the command path search instance
-
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 theCommandUsage- 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
-
getResolvedSource
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:
ImperatException- if resolution fails- See Also:
-
getContextResolvedArgument
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:
ImperatException- if resolution fails- See Also:
-
getResolvedFlags
Collection<? extends ExtractedInputFlag> getResolvedFlags()Gets all flags that were resolved from the command input.- Returns:
- a collection of resolved flags
-
resolveArgument
<T> void resolveArgument(Command<S> command, @Nullable @Nullable String raw, int index, CommandParameter<S> parameter, @Nullable T value) throws ImperatException Resolves and registers a command argument.- Type Parameters:
T- the type of the argument value- Parameters:
command- the owning commandraw- the raw input stringindex- the argument positionparameter- the parameter definitionvalue- the resolved value- Throws:
ImperatException- if resolution fails
-
resolveArgument
default <T> void resolveArgument(CommandInputStream<S> stream, @Nullable T value) throws ImperatException 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:
ImperatException- if resolution fails.
-
resolveFlag
default void resolveFlag(FlagData<S> flagDetected, String flagRaw, @Nullable @Nullable String flagInputRaw, @Nullable @Nullable Object flagInputValue) Resolves a command flag from its raw components.- Parameters:
flagDetected- the flag parameter definitionflagRaw- the raw flag string (including prefix)flagInputRaw- the raw flag value (may be null for switches)flagInputValue- the resolved flag value
-
resolveFlag
Registers a resolved flag in the context.- Parameters:
flag- the resolved flag to register
-
getLastUsedCommand
Gets the most specific command that was resolved in this context.- Returns:
- the terminal command that will be executed
-
getDetectedUsage
CommandUsage<S> getDetectedUsage()Gets the command usage pattern that matched the input.- Returns:
- the detected command usage
-
resolve
Resolves all arguments and flags from the raw context input.- Throws:
ImperatException- if resolution fails
-
getResolvedArgument
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
-
getResolvedArguments
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
-
getResolvedArguments
Collection<? extends Argument<S>> getResolvedArguments()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)
-