Package: org.apache.groovy.groovysh.jline

## [Java] Class SystemRegistryImpl

- org.apache.groovy.groovysh.jline.SystemRegistryImpl

- All Implemented Interfaces and Traits:
    SystemRegistry

      public class SystemRegistryImpl
      extends Object
      implements SystemRegistry

  Aggregate command registries.

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `protected static class` | `SystemRegistryImpl.CommandData` | Holds parsed command data for pipeline execution.
    `enum` | `SystemRegistryImpl.Pipe` | Pipe operators used to connect commands in a pipeline.
    `static class` | `SystemRegistryImpl.UnknownCommandException` | Exception thrown when a command is not recognized.

  - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected ConfigurationPath` | `configPath` | Configuration path for storing user-specific settings
    `protected Parser` | `parser` | The parser used for command line parsing
    `protected Supplier<Path>` | `workDir` | Supplier for the working directory

  - ### Constructor Summary

    Constructors
    Constructor and description
    `SystemRegistryImpl(Parser parser, Terminal terminal, Supplier<Path> workDir, ConfigurationPath configPath)` Constructs a new SystemRegistryImpl.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `addCompleter(Completer completer)` Adds a completer to the registry.
    `` | `public void` | `cleanUp()` Cleans up output streams and purges temporary data.
    `` | `public void` | `close()` Persists collected command names before shutdown.
    `` | `public Map<String, String>` | `commandAliases()` Returns all command aliases.
    `` | `public CmdDesc` | `commandDescription(List<String> args)` Returns the description for a command given its arguments.
    `` | `public CmdDesc` | `commandDescription(CmdLine line)` Returns the description for a command line.
    `` | `public List<String>` | `commandInfo(String command)` Returns the help information for a command.
    `` | `public Set<String>` | `commandNames()` Returns the names of all registered commands.
    `` | `public SystemCompleter` | `compileCompleters()` Compiles all registered completers into a system completer.
    `` | `public Completer` | `completer()` Returns the completer for all registered commands and scripts.
    `` | `public ConsoleEngine` | `consoleEngine()` Returns the console engine, if available.
    `` | `public Object` | `consoleOption(String name)` Retrieves a console option value.
    `<T>` | `public T` | `consoleOption(String name, T defVal)` Retrieves a console option value with a default.
    `` | `public Object` | `execute(String line)` Executes a command line, including pipes, redirection, and console statements.
    `` | `public Collection<String>` | `getPipeNames()` Returns the names of all pipe operators.
    `` | `public SystemRegistryImpl` | `groupCommandsInHelp(boolean commandGroups)` Sets whether commands should be grouped by registry in help output.
    `` | `public boolean` | `hasCommand(String command)` Checks if a command exists.
    `` | `public void` | `initialize(File script)` Initializes the system by executing a startup script.
    `` | `public Object` | `invoke(String command, Object args)` Invokes a command with the given arguments.
    `` | `public boolean` | `isCommandAlias(String command)` Checks if the command is an alias.
    `` | `public boolean` | `isCommandOrScript(ParsedLine line)` Checks if the parsed line represents a command or script.
    `` | `public boolean` | `isCommandOrScript(String command)` Checks if the given string represents a command or script.
    `` | `public void` | `register(String command, CommandRegistry subcommandRegistry)` Register subcommand registry
    `` | `public void` | `rename(SystemRegistryImpl.Pipe pipe, String name)` Renames a pipe operator.
    `` | `public void` | `renameLocal(String command, String newName)` Renames a local command.
    `` | `public void` | `setCommandRegistries(CommandRegistry commandRegistries)` Sets the command registries managed by this system registry.
    `` | `public void` | `setConsoleOption(String name, Object value)` Sets a console option value.
    `` | `public void` | `setGroupCommandsInHelp(boolean commandGroups)` Sets whether commands should be grouped by registry in help output.
    `` | `public void` | `setScriptDescription(Function<CmdLine, CmdDesc> scriptDescription)` Sets the function used to describe scripts for tab completion.
    `` | `public Terminal` | `terminal()` Returns the terminal associated with this registry.
    `` | `public void` | `trace(Throwable exception)` Reports an exception using the configured console-aware tracing strategy.
    `` | `public void` | `trace(boolean stack, Throwable exception)` Reports an exception, optionally printing its full stack trace.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### protected final ConfigurationPath configPath

      Configuration path for storing user-specific settings

    - #### protected final Parser parser

      The parser used for command line parsing

    - #### protected final Supplier<Path> workDir

      Supplier for the working directory

  - ### Constructor Detail

    - #### public SystemRegistryImpl(Parser parser, Terminal terminal, Supplier<Path> workDir, ConfigurationPath configPath)

      Constructs a new SystemRegistryImpl.

      Parameters:
        `parser` - the parser for command line parsing
        `terminal` - the terminal to use for input/output
        `workDir` - supplier for the working directory
        `configPath` - configuration path for user-specific settings

  - ### Method Detail

    - #### public void addCompleter(Completer completer)

      Adds a completer to the registry.

      Parameters:
        `completer` - the completer to add

    - #### public void cleanUp()

      Cleans up output streams and purges temporary data.

    - #### public void close()

      Persists collected command names before shutdown.

    - #### public Map<String, String> commandAliases()

      Returns all command aliases.

      Returns:
        map of aliases to command names

    - #### public CmdDesc commandDescription(List<String> args)

      Returns the description for a command given its arguments.

      Parameters:
        `args` - the command arguments
      Returns:
        the command description

    - #### public CmdDesc commandDescription(CmdLine line)

      Returns the description for a command line.

      Parameters:
        `line` - the command line
      Returns:
        the command description

    - #### public List<String> commandInfo(String command)

      Returns the help information for a command.

      Parameters:
        `command` - the command name
      Returns:
        list of help text lines

    - #### public Set<String> commandNames()

      Returns the names of all registered commands.

      Returns:
        set of command names

    - #### public SystemCompleter compileCompleters()

      Compiles all registered completers into a system completer.

      throws:
        IllegalStateException always; use completer() instead
      Returns:
        the system completer

    - #### public Completer completer()

      Returns the completer for all registered commands and scripts.

      Returns:
        the completer instance

    - #### public ConsoleEngine consoleEngine()

      Returns the console engine, if available.

      Returns:
        the console engine, or null if not configured

    - #### public Object consoleOption(String name)

      Retrieves a console option value.

      Parameters:
        `name` - the option name
      Returns:
        the option value, or `null` if not found

    - #### <T> public T consoleOption(String name, T defVal)

      Retrieves a console option value with a default.

      Type Parameters:
        `T` - the option value type
      Parameters:
        `name` - the option name
        `defVal` - the default value
      Returns:
        the option value, or the default if not found

    - #### public Object execute(String line)

      Executes a command line, including pipes, redirection, and console statements.

      throws:
        Exception if command execution fails
      Parameters:
        `line` - command line to execute
      Returns:
        command result, if any

    - #### public Collection<String> getPipeNames()

      Returns the names of all pipe operators.

      Returns:
        collection of pipe names

    - #### public SystemRegistryImpl groupCommandsInHelp(boolean commandGroups)

      Sets whether commands should be grouped by registry in help output.

      Parameters:
        `commandGroups` - true to group commands, false otherwise
      Returns:
        this instance for method chaining

    - #### public boolean hasCommand(String command)

      Checks if a command exists.

      Parameters:
        `command` - the command name
      Returns:
        `true` if the command exists, `false` otherwise

    - #### public void initialize(File script)

      Initializes the system by executing a startup script.

      Parameters:
        `script` - the script file to execute

    - #### public Object invoke(String command, Object args)

      Invokes a command with the given arguments.

      throws:
        Exception if command execution fails
      Parameters:
        `command` - the command name
        `args` - the command arguments
      Returns:
        the result of command execution

    - #### public boolean isCommandAlias(String command)

      Checks if the command is an alias.

      Parameters:
        `command` - the command name
      Returns:
        `true` if the command is an alias, `false` otherwise

    - #### public boolean isCommandOrScript(ParsedLine line)

      Checks if the parsed line represents a command or script.

      Parameters:
        `line` - the parsed line to check
      Returns:
        `true` if the line is a command or script, `false` otherwise

    - #### public boolean isCommandOrScript(String command)

      Checks if the given string represents a command or script.

      Parameters:
        `command` - the command name to check
      Returns:
        `true` if the command or script exists, `false` otherwise

    - #### public void register(String command, CommandRegistry subcommandRegistry)

      Register subcommand registry

      Parameters:
        `command` - main command
        `subcommandRegistry` - subcommand registry

    - #### public void rename(SystemRegistryImpl.Pipe pipe, String name)

      Renames a pipe operator.

      throws:
        IllegalArgumentException if the name is invalid or already in use
      Parameters:
        `pipe` - the pipe to rename
        `name` - the new name

    - #### public void renameLocal(String command, String newName)

      Renames a local command.

      Parameters:
        `command` - the command to rename
        `newName` - the new name for the command

    - #### public void setCommandRegistries(CommandRegistry commandRegistries)

      Sets the command registries managed by this system registry.

      Parameters:
        `commandRegistries` - the command registries to set

    - #### public void setConsoleOption(String name, Object value)

      Sets a console option value.

      Parameters:
        `name` - the option name
        `value` - the option value

    - #### public void setGroupCommandsInHelp(boolean commandGroups)

      Sets whether commands should be grouped by registry in help output.

      Parameters:
        `commandGroups` - true to group commands, false otherwise

    - #### public void setScriptDescription(Function<CmdLine, CmdDesc> scriptDescription)

      Sets the function used to describe scripts for tab completion.

      Parameters:
        `scriptDescription` - the script description function

    - #### public Terminal terminal()

      Returns the terminal associated with this registry.

      Returns:
        the terminal

    - #### public void trace(Throwable exception)

      Reports an exception using the configured console-aware tracing strategy.

      Parameters:
        `exception` - exception to report

    - #### public void trace(boolean stack, Throwable exception)

      Reports an exception, optionally printing its full stack trace.

      Parameters:
        `stack` - whether to print the full stack trace
        `exception` - exception to report