Class DefaultCommandDispatcher
- All Implemented Interfaces:
AutoCloseable,CommandDispatcher
CommandDispatcher that supports pipeline execution.
This dispatcher parses command lines using PipelineParser, resolves commands
from registered CommandGroups, and executes pipeline stages with proper
pipe/redirect/conditional handling.
When a JobManager is configured, the dispatcher supports:
- Background execution via trailing
& - Foreground job tracking
- Built-in
jobs,fg,bgcommands
When an AliasManager is configured, the dispatcher expands aliases
before pipeline parsing and automatically registers alias/unalias commands.
- Since:
- 4.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultCommandDispatcher(LineReader reader) Creates a new dispatcher for the given reader.DefaultCommandDispatcher(Terminal terminal) Creates a new dispatcher for the given terminal.DefaultCommandDispatcher(Terminal terminal, JobManager jobManager) Creates a new dispatcher for the given terminal with optional job management.DefaultCommandDispatcher(Terminal terminal, JobManager jobManager, PipelineParser pipelineParser, AliasManager aliasManager) Creates a new dispatcher with all configuration options.DefaultCommandDispatcher(Terminal terminal, JobManager jobManager, PipelineParser pipelineParser, AliasManager aliasManager, LineExpander lineExpander, ScriptRunner scriptRunner) Creates a new dispatcher with all configuration options including line expansion and script execution.DefaultCommandDispatcher(Terminal terminal, JobManager jobManager, PipelineParser pipelineParser, AliasManager aliasManager, LineExpander lineExpander, ScriptRunner scriptRunner, Parser parser) Creates a new dispatcher with all configuration options including line expansion, script execution and parser. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddGroup(CommandGroup group) Adds a command group to this dispatcher.voidclose()No-op default implementation; does nothing.Creates a completer that provides completions for every registered command name and its aliases.describe(CommandLine commandLine) Returns a description for the command at the current command line position.Executes a command line string.Executes a pre-parsed pipeline.groups()Returns all registered command groups.voidinitialize(File script) Initializes the dispatcher, optionally executing a startup script.voidInterrupts the currently executing command, if any.session()Returns the command session used by this dispatcher.terminal()Returns the terminal associated with this dispatcher.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jline.shell.CommandDispatcher
cleanUp, errorStyle, findCommand, trace
-
Constructor Details
-
DefaultCommandDispatcher
Creates a new dispatcher for the given terminal.- Parameters:
terminal- the terminal
-
DefaultCommandDispatcher
Creates a new dispatcher for the given reader.- Parameters:
reader- the reader
-
DefaultCommandDispatcher
Creates a new dispatcher for the given terminal with optional job management.- Parameters:
terminal- the terminaljobManager- the job manager, or null for no job control
-
DefaultCommandDispatcher
public DefaultCommandDispatcher(Terminal terminal, JobManager jobManager, PipelineParser pipelineParser, AliasManager aliasManager) Creates a new dispatcher with all configuration options.When a non-null
JobManageris provided, the dispatcher automatically registersJobCommandsand supports background execution via trailing&.When a non-null
AliasManageris provided, the dispatcher expands aliases before pipeline parsing and automatically registersAliasCommands.When a non-null
PipelineParseris provided, it is used instead of the default parser. This allows custom operator registration and subclass overrides.- Parameters:
terminal- the terminaljobManager- the job manager, or null for no job controlpipelineParser- the pipeline parser, or null for the default parseraliasManager- the alias manager, or null for no alias support
-
DefaultCommandDispatcher
public DefaultCommandDispatcher(Terminal terminal, JobManager jobManager, PipelineParser pipelineParser, AliasManager aliasManager, LineExpander lineExpander, ScriptRunner scriptRunner) Creates a new dispatcher with all configuration options including line expansion and script execution.- Parameters:
terminal- the terminaljobManager- the job manager, or null for no job controlpipelineParser- the pipeline parser, or null for the default parseraliasManager- the alias manager, or null for no alias supportlineExpander- the line expander, or null for no variable expansionscriptRunner- the script runner, or null for no script support
-
DefaultCommandDispatcher
public DefaultCommandDispatcher(Terminal terminal, JobManager jobManager, PipelineParser pipelineParser, AliasManager aliasManager, LineExpander lineExpander, ScriptRunner scriptRunner, Parser parser) Creates a new dispatcher with all configuration options including line expansion, script execution and parser.- Parameters:
terminal- the terminaljobManager- the job manager, or null for no job controlpipelineParser- the pipeline parser, or null for the default parseraliasManager- the alias manager, or null for no alias supportlineExpander- the line expander, or null for no variable expansionscriptRunner- the script runner, or null for no script supportparser- the argument parser, or null for the default parser
-
-
Method Details
-
addGroup
Description copied from interface:CommandDispatcherAdds a command group to this dispatcher.- Specified by:
addGroupin interfaceCommandDispatcher- Parameters:
group- the command group to add
-
groups
Description copied from interface:CommandDispatcherReturns all registered command groups.- Specified by:
groupsin interfaceCommandDispatcher- Returns:
- the list of command groups
-
execute
Description copied from interface:CommandDispatcherExecutes a command line string.The dispatcher parses the line (potentially into a pipeline) and executes the commands.
- Specified by:
executein interfaceCommandDispatcher- Parameters:
line- the command line to execute- Returns:
- the result of execution
- Throws:
Exception- if execution fails
-
execute
Description copied from interface:CommandDispatcherExecutes a pre-parsed pipeline.- Specified by:
executein interfaceCommandDispatcher- Parameters:
pipeline- the pipeline to execute- Returns:
- the result of execution
- Throws:
Exception- if execution fails
-
completer
Creates a completer that provides completions for every registered command name and its aliases. Builds a SystemCompleter, registers a completer for each command and each of its alias strings, and finalizes it into a candidate-producing completer.- Specified by:
completerin interfaceCommandDispatcher- Returns:
- a Completer that offers argument and command-name completions for all registered commands and aliases
-
describe
Description copied from interface:CommandDispatcherReturns a description for the command at the current command line position.Used by widgets for context-sensitive help.
- Specified by:
describein interfaceCommandDispatcher- Parameters:
commandLine- the parsed command line- Returns:
- the command description, or null
-
terminal
Description copied from interface:CommandDispatcherReturns the terminal associated with this dispatcher.- Specified by:
terminalin interfaceCommandDispatcher- Returns:
- the terminal
-
session
Returns the command session used by this dispatcher.- Returns:
- the command session
-
interruptCurrentCommand
public void interruptCurrentCommand()Interrupts the currently executing command, if any.This is typically called from a signal handler (e.g., SIGINT) to interrupt the foreground command without killing the shell.
-
initialize
Description copied from interface:CommandDispatcherInitializes the dispatcher, optionally executing a startup script.- Specified by:
initializein interfaceCommandDispatcher- Parameters:
script- the initialization script, or null- Throws:
Exception- if initialization fails
-
close
public void close()No-op default implementation; does nothing. Subclasses may override to release or close allocated resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCommandDispatcher
-