Class DefaultCommandDispatcher

java.lang.Object
org.jline.shell.impl.DefaultCommandDispatcher
All Implemented Interfaces:
AutoCloseable, CommandDispatcher

public class DefaultCommandDispatcher extends Object implements CommandDispatcher
Default implementation of 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, bg commands

When an AliasManager is configured, the dispatcher expands aliases before pipeline parsing and automatically registers alias/unalias commands.

Since:
4.0
See Also:
  • Constructor Details

    • DefaultCommandDispatcher

      public DefaultCommandDispatcher(org.jline.terminal.Terminal terminal)
      Creates a new dispatcher for the given terminal.
      Parameters:
      terminal - the terminal
    • DefaultCommandDispatcher

      public DefaultCommandDispatcher(org.jline.reader.LineReader reader)
      Creates a new dispatcher for the given reader.
      Parameters:
      reader - the reader
    • DefaultCommandDispatcher

      public DefaultCommandDispatcher(org.jline.terminal.Terminal terminal, JobManager jobManager)
      Creates a new dispatcher for the given terminal with optional job management.
      Parameters:
      terminal - the terminal
      jobManager - the job manager, or null for no job control
    • DefaultCommandDispatcher

      public DefaultCommandDispatcher(org.jline.terminal.Terminal terminal, JobManager jobManager, PipelineParser pipelineParser, AliasManager aliasManager)
      Creates a new dispatcher with all configuration options.

      When a non-null JobManager is provided, the dispatcher automatically registers JobCommands and supports background execution via trailing &.

      When a non-null AliasManager is provided, the dispatcher expands aliases before pipeline parsing and automatically registers AliasCommands.

      When a non-null PipelineParser is provided, it is used instead of the default parser. This allows custom operator registration and subclass overrides.

      Parameters:
      terminal - the terminal
      jobManager - the job manager, or null for no job control
      pipelineParser - the pipeline parser, or null for the default parser
      aliasManager - the alias manager, or null for no alias support
    • DefaultCommandDispatcher

      public DefaultCommandDispatcher(org.jline.terminal.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 terminal
      jobManager - the job manager, or null for no job control
      pipelineParser - the pipeline parser, or null for the default parser
      aliasManager - the alias manager, or null for no alias support
      lineExpander - the line expander, or null for no variable expansion
      scriptRunner - the script runner, or null for no script support
    • DefaultCommandDispatcher

      public DefaultCommandDispatcher(org.jline.terminal.Terminal terminal, JobManager jobManager, PipelineParser pipelineParser, AliasManager aliasManager, LineExpander lineExpander, ScriptRunner scriptRunner, org.jline.reader.Parser parser)
      Creates a new dispatcher with all configuration options including line expansion, script execution and parser.
      Parameters:
      terminal - the terminal
      jobManager - the job manager, or null for no job control
      pipelineParser - the pipeline parser, or null for the default parser
      aliasManager - the alias manager, or null for no alias support
      lineExpander - the line expander, or null for no variable expansion
      scriptRunner - the script runner, or null for no script support
      parser - the argument parser, or null for the default parser
  • Method Details

    • addGroup

      public void addGroup(CommandGroup group)
      Description copied from interface: CommandDispatcher
      Adds a command group to this dispatcher.
      Specified by:
      addGroup in interface CommandDispatcher
      Parameters:
      group - the command group to add
    • groups

      public List<CommandGroup> groups()
      Description copied from interface: CommandDispatcher
      Returns all registered command groups.
      Specified by:
      groups in interface CommandDispatcher
      Returns:
      the list of command groups
    • execute

      public Object execute(String line) throws Exception
      Description copied from interface: CommandDispatcher
      Executes a command line string.

      The dispatcher parses the line (potentially into a pipeline) and executes the commands.

      Specified by:
      execute in interface CommandDispatcher
      Parameters:
      line - the command line to execute
      Returns:
      the result of execution
      Throws:
      Exception - if execution fails
    • execute

      public Object execute(Pipeline pipeline) throws Exception
      Description copied from interface: CommandDispatcher
      Executes a pre-parsed pipeline.
      Specified by:
      execute in interface CommandDispatcher
      Parameters:
      pipeline - the pipeline to execute
      Returns:
      the result of execution
      Throws:
      Exception - if execution fails
    • completer

      public org.jline.reader.Completer 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:
      completer in interface CommandDispatcher
      Returns:
      a Completer that offers argument and command-name completions for all registered commands and aliases
    • describe

      public CommandDescription describe(CommandLine commandLine)
      Description copied from interface: CommandDispatcher
      Returns a description for the command at the current command line position.

      Used by widgets for context-sensitive help.

      Specified by:
      describe in interface CommandDispatcher
      Parameters:
      commandLine - the parsed command line
      Returns:
      the command description, or null
    • terminal

      public org.jline.terminal.Terminal terminal()
      Description copied from interface: CommandDispatcher
      Returns the terminal associated with this dispatcher.
      Specified by:
      terminal in interface CommandDispatcher
      Returns:
      the terminal
    • session

      public CommandSession 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

      public void initialize(File script) throws Exception
      Description copied from interface: CommandDispatcher
      Initializes the dispatcher, optionally executing a startup script.
      Specified by:
      initialize in interface CommandDispatcher
      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:
      close in interface AutoCloseable
      Specified by:
      close in interface CommandDispatcher