Interface CommandRegistry

All Known Subinterfaces:
ConsoleEngine, SystemRegistry
All Known Implementing Classes:
AbstractCommandRegistry, Builtins, ConsoleEngineImpl, DefaultPrinter, JlineCommandRegistry, SimpleSystemRegistryImpl, SystemRegistryImpl

public interface CommandRegistry
Interface for registering, describing, and executing commands in a console application.

The CommandRegistry provides methods for managing a set of commands, including:

  • Registering commands and their aliases
  • Providing command descriptions and usage information
  • Executing commands with arguments
  • Creating command completers for tab completion

Implementations of this interface can be used to create custom command registries for specific domains or applications.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    Class representing a command execution session.
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.jline.reader.impl.completer.SystemCompleter
    aggregateCompleters(CommandRegistry... commandRegistries)
    Aggregates SystemCompleters from multiple command registries into a single completer.
    Returns a map of alias-to-command names known by this registry.
    Returns a command description for use in the JLine Widgets framework.
    Returns a short info about command known by this registry.
    Returns the command names known by this registry.
    org.jline.reader.impl.completer.SystemCompleter
    Returns a SystemCompleter that can provide detailed completion information for all registered commands.
    static org.jline.reader.impl.completer.SystemCompleter
    compileCompleters(CommandRegistry... commandRegistries)
    Aggregates and compiles SystemCompleters from multiple command registries into a single completer.
    static org.jline.reader.Candidate
    createCandidate(CommandRegistry[] commandRegistries, String command)
    Creates a completion candidate for the specified command.
    boolean
    hasCommand(String command)
    Returns whether a command with the specified name is known to this registry.
    default Object
    invoke(CommandRegistry.CommandSession session, String command, Object... args)
    Execute a command.
    default String
    Returns the name of this registry.
  • Method Details

    • aggregateCompleters

      static org.jline.reader.impl.completer.SystemCompleter aggregateCompleters(CommandRegistry... commandRegistries)
      Aggregates SystemCompleters from multiple command registries into a single completer.

      This method combines the completers from all provided command registries without compiling them. The resulting completer can be used for tab completion across all commands from the provided registries.

      Parameters:
      commandRegistries - the command registries whose completers are to be aggregated
      Returns:
      an uncompiled SystemCompleter containing all completers from the provided registries
    • compileCompleters

      static org.jline.reader.impl.completer.SystemCompleter compileCompleters(CommandRegistry... commandRegistries)
      Aggregates and compiles SystemCompleters from multiple command registries into a single completer.

      This method combines the completers from all provided command registries and compiles them into a single completer. The resulting completer can be used for tab completion across all commands from the provided registries.

      Parameters:
      commandRegistries - the command registries whose completers are to be aggregated and compiled
      Returns:
      a compiled SystemCompleter containing all completers from the provided registries
    • createCandidate

      static org.jline.reader.Candidate createCandidate(CommandRegistry[] commandRegistries, String command)
      Creates a completion candidate for the specified command.

      This method searches for the command in the provided registries and creates a completion candidate with the command's name, group, and description.

      Parameters:
      commandRegistries - the command registries to search for the command
      command - the command name
      Returns:
      a completion candidate for the command
    • name

      default String name()
      Returns the name of this registry.
      Returns:
      the name of the registry
    • commandNames

      Set<String> commandNames()
      Returns the command names known by this registry.
      Returns:
      the set of known command names, excluding aliases
    • commandAliases

      Map<String,String> commandAliases()
      Returns a map of alias-to-command names known by this registry.
      Returns:
      a map with alias keys and command name values
    • commandInfo

      List<String> commandInfo(String command)
      Returns a short info about command known by this registry.
      Parameters:
      command - the command name
      Returns:
      a short info about command
    • hasCommand

      boolean hasCommand(String command)
      Returns whether a command with the specified name is known to this registry.
      Parameters:
      command - the command name to test
      Returns:
      true if the specified command is registered
    • compileCompleters

      org.jline.reader.impl.completer.SystemCompleter compileCompleters()
      Returns a SystemCompleter that can provide detailed completion information for all registered commands.
      Returns:
      a SystemCompleter that can provide command completion for all registered commands
    • commandDescription

      CmdDesc commandDescription(List<String> args)
      Returns a command description for use in the JLine Widgets framework. Default method must be overridden to return sub command descriptions.
      Parameters:
      args - command (args[0]) and its arguments
      Returns:
      command description for JLine TailTipWidgets to be displayed in the terminal status bar.
    • invoke

      default Object invoke(CommandRegistry.CommandSession session, String command, Object... args) throws Exception
      Execute a command.
      Parameters:
      session - the data of the current command session
      command - the name of the command
      args - arguments of the command
      Returns:
      result of the command execution
      Throws:
      Exception - in case of error