Package org.apache.groovy.groovysh.jline
Class SystemRegistryImpl
java.lang.Object
org.apache.groovy.groovysh.jline.SystemRegistryImpl
- All Implemented Interfaces:
org.jline.builtins.ConsoleOptionGetter,org.jline.console.CommandRegistry,org.jline.console.SystemRegistry
Aggregate command registries.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classHolds parsed command data for pipeline execution.static enumPipe operators used to connect commands in a pipeline.static classException thrown when a command is not recognized.Nested classes/interfaces inherited from interface org.jline.console.CommandRegistry
org.jline.console.CommandRegistry.CommandSessionNested classes/interfaces inherited from interface org.jline.console.SystemRegistry
org.jline.console.SystemRegistry.Registeries -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.jline.builtins.ConfigurationPathConfiguration path for storing user-specific settingsprotected final org.jline.reader.ParserThe parser used for command line parsingSupplier for the working directory -
Constructor Summary
ConstructorsConstructorDescriptionSystemRegistryImpl(org.jline.reader.Parser parser, org.jline.terminal.Terminal terminal, Supplier<Path> workDir, org.jline.builtins.ConfigurationPath configPath) Constructs a new SystemRegistryImpl. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCompleter(org.jline.reader.Completer completer) Adds a completer to the registry.voidcleanUp()Cleans up output streams and purges temporary data.voidclose()Persists collected command names before shutdown.Returns all command aliases.org.jline.console.CmdDesccommandDescription(List<String> args) Returns the description for a command given its arguments.org.jline.console.CmdDesccommandDescription(org.jline.console.CmdLine line) Returns the description for a command line.commandInfo(String command) Returns the help information for a command.Returns the names of all registered commands.org.jline.reader.impl.completer.SystemCompleterCompiles all registered completers into a system completer.org.jline.reader.CompleterReturns the completer for all registered commands and scripts.org.jline.console.ConsoleEngineReturns the console engine, if available.consoleOption(String name) Retrieves a console option value.<T> TconsoleOption(String name, T defVal) Retrieves a console option value with a default.Executes a command line, including pipes, redirection, and console statements.Returns the names of all pipe operators.groupCommandsInHelp(boolean commandGroups) Sets whether commands should be grouped by registry in help output.booleanhasCommand(String command) Checks if a command exists.voidinitialize(File script) Initializes the system by executing a startup script.Invokes a command with the given arguments.booleanisCommandAlias(String command) Checks if the command is an alias.booleanisCommandOrScript(String command) Checks if the given string represents a command or script.booleanisCommandOrScript(org.jline.reader.ParsedLine line) Checks if the parsed line represents a command or script.voidRegister subcommand registryvoidrename(SystemRegistryImpl.Pipe pipe, String name) Renames a pipe operator.voidrenameLocal(String command, String newName) Renames a local command.voidsetCommandRegistries(org.jline.console.CommandRegistry... commandRegistries) Sets the command registries managed by this system registry.voidsetConsoleOption(String name, Object value) Sets a console option value.voidsetGroupCommandsInHelp(boolean commandGroups) Sets whether commands should be grouped by registry in help output.voidsetScriptDescription(Function<org.jline.console.CmdLine, org.jline.console.CmdDesc> scriptDescription) Sets the function used to describe scripts for tab completion.org.jline.terminal.Terminalterminal()Returns the terminal associated with this registry.voidReports an exception, optionally printing its full stack trace.voidReports an exception using the configured console-aware tracing strategy.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jline.console.CommandRegistry
invoke, name
-
Field Details
-
parser
protected final org.jline.reader.Parser parserThe parser used for command line parsing -
configPath
protected final org.jline.builtins.ConfigurationPath configPathConfiguration path for storing user-specific settings -
workDir
Supplier for the working directory
-
-
Constructor Details
-
SystemRegistryImpl
public SystemRegistryImpl(org.jline.reader.Parser parser, org.jline.terminal.Terminal terminal, Supplier<Path> workDir, org.jline.builtins.ConfigurationPath configPath) Constructs a new SystemRegistryImpl.- Parameters:
parser- the parser for command line parsingterminal- the terminal to use for input/outputworkDir- supplier for the working directoryconfigPath- configuration path for user-specific settings
-
-
Method Details
-
rename
Renames a pipe operator.- Parameters:
pipe- the pipe to renamename- the new name- Throws:
IllegalArgumentException- if the name is invalid or already in use
-
renameLocal
Renames a local command.- Parameters:
command- the command to renamenewName- the new name for the command
-
getPipeNames
Returns the names of all pipe operators.- Specified by:
getPipeNamesin interfaceorg.jline.console.SystemRegistry- Returns:
- collection of pipe names
-
setCommandRegistries
public void setCommandRegistries(org.jline.console.CommandRegistry... commandRegistries) Sets the command registries managed by this system registry.- Specified by:
setCommandRegistriesin interfaceorg.jline.console.SystemRegistry- Parameters:
commandRegistries- the command registries to set
-
initialize
Initializes the system by executing a startup script.- Specified by:
initializein interfaceorg.jline.console.SystemRegistry- Parameters:
script- the script file to execute
-
commandNames
Returns the names of all registered commands.- Specified by:
commandNamesin interfaceorg.jline.console.CommandRegistry- Returns:
- set of command names
-
commandAliases
Returns all command aliases.- Specified by:
commandAliasesin interfaceorg.jline.console.CommandRegistry- Returns:
- map of aliases to command names
-
consoleOption
Retrieves a console option value.- Specified by:
consoleOptionin interfaceorg.jline.builtins.ConsoleOptionGetter- Specified by:
consoleOptionin interfaceorg.jline.console.SystemRegistry- Parameters:
name- the option name- Returns:
- the option value, or
nullif not found
-
consoleOption
Retrieves a console option value with a default.- Specified by:
consoleOptionin interfaceorg.jline.builtins.ConsoleOptionGetter- Specified by:
consoleOptionin interfaceorg.jline.console.SystemRegistry- Type Parameters:
T- the option value type- Parameters:
name- the option namedefVal- the default value- Returns:
- the option value, or the default if not found
-
setConsoleOption
Sets a console option value.- Specified by:
setConsoleOptionin interfaceorg.jline.console.SystemRegistry- Parameters:
name- the option namevalue- the option value
-
register
Register subcommand registry- Specified by:
registerin interfaceorg.jline.console.SystemRegistry- Parameters:
command- main commandsubcommandRegistry- subcommand registry
-
commandInfo
Returns the help information for a command.- Specified by:
commandInfoin interfaceorg.jline.console.CommandRegistry- Parameters:
command- the command name- Returns:
- list of help text lines
-
hasCommand
Checks if a command exists.- Specified by:
hasCommandin interfaceorg.jline.console.CommandRegistry- Parameters:
command- the command name- Returns:
trueif the command exists,falseotherwise
-
setGroupCommandsInHelp
public void setGroupCommandsInHelp(boolean commandGroups) Sets whether commands should be grouped by registry in help output.- Parameters:
commandGroups- true to group commands, false otherwise
-
groupCommandsInHelp
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
-
isCommandOrScript
public boolean isCommandOrScript(org.jline.reader.ParsedLine line) Checks if the parsed line represents a command or script.- Specified by:
isCommandOrScriptin interfaceorg.jline.console.SystemRegistry- Parameters:
line- the parsed line to check- Returns:
trueif the line is a command or script,falseotherwise
-
isCommandOrScript
Checks if the given string represents a command or script.- Specified by:
isCommandOrScriptin interfaceorg.jline.console.SystemRegistry- Parameters:
command- the command name to check- Returns:
trueif the command or script exists,falseotherwise
-
addCompleter
public void addCompleter(org.jline.reader.Completer completer) Adds a completer to the registry.- Parameters:
completer- the completer to add
-
compileCompleters
public org.jline.reader.impl.completer.SystemCompleter compileCompleters()Compiles all registered completers into a system completer.- Specified by:
compileCompletersin interfaceorg.jline.console.CommandRegistry- Returns:
- the system completer
- Throws:
IllegalStateException- always; usecompleter()instead
-
completer
public org.jline.reader.Completer completer()Returns the completer for all registered commands and scripts.- Specified by:
completerin interfaceorg.jline.console.SystemRegistry- Returns:
- the completer instance
-
commandDescription
Returns the description for a command given its arguments.- Specified by:
commandDescriptionin interfaceorg.jline.console.CommandRegistry- Parameters:
args- the command arguments- Returns:
- the command description
-
setScriptDescription
public void setScriptDescription(Function<org.jline.console.CmdLine, org.jline.console.CmdDesc> scriptDescription) Sets the function used to describe scripts for tab completion.- Parameters:
scriptDescription- the script description function
-
commandDescription
public org.jline.console.CmdDesc commandDescription(org.jline.console.CmdLine line) Returns the description for a command line.- Specified by:
commandDescriptionin interfaceorg.jline.console.SystemRegistry- Parameters:
line- the command line- Returns:
- the command description
-
invoke
Invokes a command with the given arguments.- Specified by:
invokein interfaceorg.jline.console.SystemRegistry- Parameters:
command- the command nameargs- the command arguments- Returns:
- the result of command execution
- Throws:
Exception- if command execution fails
-
terminal
public org.jline.terminal.Terminal terminal()Returns the terminal associated with this registry.- Specified by:
terminalin interfaceorg.jline.console.SystemRegistry- Returns:
- the terminal
-
isCommandAlias
Checks if the command is an alias.- Specified by:
isCommandAliasin interfaceorg.jline.console.SystemRegistry- Parameters:
command- the command name- Returns:
trueif the command is an alias,falseotherwise
-
execute
Executes a command line, including pipes, redirection, and console statements.- Specified by:
executein interfaceorg.jline.console.SystemRegistry- Parameters:
line- command line to execute- Returns:
- command result, if any
- Throws:
Exception- if command execution fails
-
cleanUp
public void cleanUp()Cleans up output streams and purges temporary data.- Specified by:
cleanUpin interfaceorg.jline.console.SystemRegistry
-
trace
Reports an exception using the configured console-aware tracing strategy.- Specified by:
tracein interfaceorg.jline.console.SystemRegistry- Parameters:
exception- exception to report
-
trace
Reports an exception, optionally printing its full stack trace.- Specified by:
tracein interfaceorg.jline.console.SystemRegistry- Parameters:
stack- whether to print the full stack traceexception- exception to report
-
close
public void close()Persists collected command names before shutdown.- Specified by:
closein interfaceorg.jline.console.SystemRegistry
-
consoleEngine
public org.jline.console.ConsoleEngine consoleEngine()Returns the console engine, if available.- Returns:
- the console engine, or null if not configured
-