Package org.jline.shell
Interface CommandDispatcher
-
- All Superinterfaces:
java.lang.AutoCloseable
- All Known Implementing Classes:
DefaultCommandDispatcher
public interface CommandDispatcher extends java.lang.AutoCloseableCentral dispatcher that aggregatesCommandGroups and handles command resolution, execution, and completion.CommandDispatcherseparates the aggregation and dispatch role from individual command semantics defined inCommandandCommandGroup.Example:
CommandDispatcher dispatcher = new DefaultCommandDispatcher(terminal); dispatcher.addGroup(myGroup); Object result = dispatcher.execute("echo hello | grep h");- Since:
- 4.0
- See Also:
CommandGroup,Command,DefaultCommandDispatcher
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaddGroup(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.Completercompleter()Returns a completer that provides tab completion across all registered commands.CommandDescriptiondescribe(CommandLine commandLine)Returns a description for the command at the current command line position.default AttributedStyleerrorStyle()java.lang.Objectexecute(java.lang.String line)Executes a command line string.java.lang.Objectexecute(Pipeline pipeline)Executes a pre-parsed pipeline.default CommandfindCommand(java.lang.String name)Finds a command by name or alias across all registered groups.java.util.List<CommandGroup>groups()Returns all registered command groups.default voidinitialize(java.io.File script)Initializes the dispatcher, optionally executing a startup script.Terminalterminal()Returns the terminal associated with this dispatcher.default voidtrace(java.lang.Throwable exception)Traces an exception (e.g., prints it to the terminal).
-
-
-
Method Detail
-
addGroup
void addGroup(CommandGroup group)
Adds a command group to this dispatcher.- Parameters:
group- the command group to add
-
groups
java.util.List<CommandGroup> groups()
Returns all registered command groups.- Returns:
- the list of command groups
-
findCommand
default Command findCommand(java.lang.String name)
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
java.lang.Object execute(java.lang.String line) throws java.lang.ExceptionExecutes 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:
java.lang.Exception- if execution fails
-
execute
java.lang.Object execute(Pipeline pipeline) throws java.lang.Exception
Executes a pre-parsed pipeline.- Parameters:
pipeline- the pipeline to execute- Returns:
- the result of execution
- Throws:
java.lang.Exception- if execution fails
-
completer
Completer completer()
Returns a completer that provides tab completion across all registered commands.- Returns:
- the aggregated completer
-
describe
CommandDescription describe(CommandLine commandLine)
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
Terminal terminal()
Returns the terminal associated with this dispatcher.- Returns:
- the terminal
-
initialize
default void initialize(java.io.File script) throws java.lang.ExceptionInitializes the dispatcher, optionally executing a startup script.- Parameters:
script- the initialization script, or null- Throws:
java.lang.Exception- if initialization fails
-
cleanUp
default void cleanUp()
Performs cleanup between command executions (e.g., resetting state).
-
errorStyle
default AttributedStyle errorStyle()
- Returns:
- A
AttributedStyleto be used when printing exception messages.
-
trace
default void trace(java.lang.Throwable exception)
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 interfacejava.lang.AutoCloseable
-
-