- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DefaultCommandDispatcher
Central dispatcher that aggregates
CommandGroups and handles
command resolution, execution, and completion.
CommandDispatcher separates the aggregation and dispatch role
from individual command semantics defined in Command and
CommandGroup.
Example:
CommandDispatcher dispatcher = new DefaultCommandDispatcher(terminal);
dispatcher.addGroup(myGroup);
Object result = dispatcher.execute("echo hello | grep h");
- Since:
- 4.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddGroup(CommandGroup group) Adds a command group to this dispatcher.default voidcleanUp()Performs cleanup between command executions (e.g., resetting state).voidclose()Closes this dispatcher and releases resources.org.jline.reader.CompleterReturns a completer that provides tab completion across all registered commands.describe(CommandLine commandLine) Returns a description for the command at the current command line position.default org.jline.utils.AttributedStyleExecutes a command line string.Executes a pre-parsed pipeline.default CommandfindCommand(String name) Finds a command by name or alias across all registered groups.groups()Returns all registered command groups.default voidinitialize(File script) Initializes the dispatcher, optionally executing a startup script.org.jline.terminal.Terminalterminal()Returns the terminal associated with this dispatcher.default voidTraces an exception (e.g., prints it to the terminal).
-
Method Details
-
addGroup
Adds a command group to this dispatcher.- Parameters:
group- the command group to add
-
groups
List<CommandGroup> groups()Returns all registered command groups.- Returns:
- the list of command groups
-
findCommand
Finds a command by name or alias across all registered groups.- Parameters:
name- the command name or alias- Returns:
- the command, or null if not found
-
execute
Executes a command line string.The dispatcher parses the line (potentially into a pipeline) and executes the commands.
- Parameters:
line- the command line to execute- Returns:
- the result of execution
- Throws:
Exception- if execution fails
-
execute
Executes a pre-parsed pipeline.- Parameters:
pipeline- the pipeline to execute- Returns:
- the result of execution
- Throws:
Exception- if execution fails
-
completer
org.jline.reader.Completer completer()Returns a completer that provides tab completion across all registered commands.- Returns:
- the aggregated completer
-
describe
Returns a description for the command at the current command line position.Used by widgets for context-sensitive help.
- Parameters:
commandLine- the parsed command line- Returns:
- the command description, or null
-
terminal
org.jline.terminal.Terminal terminal()Returns the terminal associated with this dispatcher.- Returns:
- the terminal
-
initialize
Initializes the dispatcher, optionally executing a startup script.- Parameters:
script- the initialization script, or null- Throws:
Exception- if initialization fails
-
cleanUp
default void cleanUp()Performs cleanup between command executions (e.g., resetting state). -
errorStyle
default org.jline.utils.AttributedStyle errorStyle()- Returns:
- A
AttributedStyleto be used when printing exception messages.
-
trace
Traces an exception (e.g., prints it to the terminal).- Parameters:
exception- the exception to trace
-
close
void close()Closes this dispatcher and releases resources.- Specified by:
closein interfaceAutoCloseable
-