Class SystemRegistryImpl
- java.lang.Object
-
- org.jline.console.impl.SystemRegistryImpl
-
- All Implemented Interfaces:
ConsoleOptionGetter,CommandRegistry,SystemRegistry
- Direct Known Subclasses:
SimpleSystemRegistryImpl
public class SystemRegistryImpl extends java.lang.Object implements SystemRegistry
Aggregate command registries.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classSystemRegistryImpl.CommandDatastatic classSystemRegistryImpl.Pipestatic classSystemRegistryImpl.UnknownCommandException-
Nested classes/interfaces inherited from interface org.jline.console.CommandRegistry
CommandRegistry.CommandSession
-
Nested classes/interfaces inherited from interface org.jline.console.SystemRegistry
SystemRegistry.Registeries
-
-
Field Summary
Fields Modifier and Type Field Description protected ConfigurationPathconfigPathprotected Parserparserprotected java.util.function.Supplier<java.nio.file.Path>workDir
-
Constructor Summary
Constructors Constructor Description SystemRegistryImpl(Parser parser, Terminal terminal, java.util.function.Supplier<java.nio.file.Path> workDir, ConfigurationPath configPath)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCompleter(Completer completer)voidcleanUp()Deletes temporary console variables and resets output streams.voidclose()Orderly closes this system registry.java.util.Map<java.lang.String,java.lang.String>commandAliases()Returns a map of alias-to-command names known by this registry.CmdDesccommandDescription(java.util.List<java.lang.String> args)Returns a command description for use in the JLine Widgets framework.CmdDesccommandDescription(CmdLine line)Returns a description for a command, method, or syntax for use in the JLine Widgets framework.java.util.List<java.lang.String>commandInfo(java.lang.String command)Returns a short info about command known by this registry.java.util.Set<java.lang.String>commandNames()Returns the command names known by this registry.SystemCompletercompileCompleters()Returns aSystemCompleterthat can provide detailed completion information for all registered commands.Completercompleter()Returns a command completer that includes console variable and script completion.ConsoleEngineconsoleEngine()java.lang.ObjectconsoleOption(java.lang.String name)Returns the value of a console option.<T> TconsoleOption(java.lang.String name, T defVal)Returns the value of a console option with a default value if the option doesn't exist.java.lang.Objectexecute(java.lang.String line)Executes a command, script, or evaluates a script engine statement.java.util.Collection<java.lang.String>getPipeNames()Returns the names of all pipes defined in this system registry.SystemRegistryImplgroupCommandsInHelp(boolean commandGroups)booleanhasCommand(java.lang.String command)Returns whether a command with the specified name is known to this registry.voidinitialize(java.io.File script)Initializes the console engine environment by executing a console script.java.lang.Objectinvoke(java.lang.String command, java.lang.Object... args)Executes a command with the specified arguments.booleanisCommandAlias(java.lang.String command)Checks if an alias is a known command alias.booleanisCommandOrScript(java.lang.String command)Checks if a command or script is known to this registry.booleanisCommandOrScript(ParsedLine line)Checks if a parsed line contains a command or script that is known to this registry.voidregister(java.lang.String command, CommandRegistry subcommandRegistry)Register subcommand registryvoidrename(SystemRegistryImpl.Pipe pipe, java.lang.String name)voidrenameLocal(java.lang.String command, java.lang.String newName)voidsetCommandRegistries(CommandRegistry... commandRegistries)Sets the command registries to be used by this system registry.voidsetConsoleOption(java.lang.String name, java.lang.Object value)Sets the value of a console option.voidsetGroupCommandsInHelp(boolean commandGroups)voidsetScriptDescription(java.util.function.Function<CmdLine,CmdDesc> scriptDescription)Terminalterminal()Returns the terminal associated with this system registry.voidtrace(boolean stack, java.lang.Throwable exception)Prints an exception on the terminal with control over stack trace display.voidtrace(java.lang.Throwable exception)Prints an exception on the terminal.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jline.console.CommandRegistry
invoke, name
-
-
-
-
Field Detail
-
parser
protected final Parser parser
-
configPath
protected final ConfigurationPath configPath
-
workDir
protected final java.util.function.Supplier<java.nio.file.Path> workDir
-
-
Constructor Detail
-
SystemRegistryImpl
public SystemRegistryImpl(Parser parser, Terminal terminal, java.util.function.Supplier<java.nio.file.Path> workDir, ConfigurationPath configPath)
-
-
Method Detail
-
rename
public void rename(SystemRegistryImpl.Pipe pipe, java.lang.String name)
-
renameLocal
public void renameLocal(java.lang.String command, java.lang.String newName)
-
getPipeNames
public java.util.Collection<java.lang.String> getPipeNames()
Description copied from interface:SystemRegistryReturns the names of all pipes defined in this system registry.This method retrieves the names of all pipes that have been defined in this system registry. Pipes are used to connect the output of one command to the input of another.
- Specified by:
getPipeNamesin interfaceSystemRegistry- Returns:
- a collection of pipe names defined in this system registry
-
setCommandRegistries
public void setCommandRegistries(CommandRegistry... commandRegistries)
Description copied from interface:SystemRegistrySets the command registries to be used by this system registry.This method configures the command registries that will be aggregated by this system registry. Commands from all of these registries will be available for execution through this system registry.
- Specified by:
setCommandRegistriesin interfaceSystemRegistry- Parameters:
commandRegistries- the command registries to be used by the application
-
initialize
public void initialize(java.io.File script)
Description copied from interface:SystemRegistryInitializes the console engine environment by executing a console script.This method executes the specified script to initialize the console engine environment. The script can set up variables, aliases, and other configuration needed for the console application.
- Specified by:
initializein interfaceSystemRegistry- Parameters:
script- the initialization script to execute
-
commandNames
public java.util.Set<java.lang.String> commandNames()
Description copied from interface:CommandRegistryReturns the command names known by this registry.- Specified by:
commandNamesin interfaceCommandRegistry- Returns:
- the set of known command names, excluding aliases
-
commandAliases
public java.util.Map<java.lang.String,java.lang.String> commandAliases()
Description copied from interface:CommandRegistryReturns a map of alias-to-command names known by this registry.- Specified by:
commandAliasesin interfaceCommandRegistry- Returns:
- a map with alias keys and command name values
-
consoleOption
public java.lang.Object consoleOption(java.lang.String name)
Description copied from interface:SystemRegistryReturns the value of a console option.This method retrieves the value of the console option with the specified name. Console options are used to configure the behavior of the console and its components.
- Specified by:
consoleOptionin interfaceConsoleOptionGetter- Specified by:
consoleOptionin interfaceSystemRegistry- Parameters:
name- the name of the option to retrieve- Returns:
- the value of the option, or null if the option doesn't exist
-
consoleOption
public <T> T consoleOption(java.lang.String name, T defVal)Description copied from interface:SystemRegistryReturns the value of a console option with a default value if the option doesn't exist.This method retrieves the value of the console option with the specified name, returning a default value if the option doesn't exist. Console options are used to configure the behavior of the console and its components.
- Specified by:
consoleOptionin interfaceConsoleOptionGetter- Specified by:
consoleOptionin interfaceSystemRegistry- Type Parameters:
T- the type of the option value- Parameters:
name- the name of the option to retrievedefVal- the default value to return if the option doesn't exist- Returns:
- the value of the option, or the default value if the option doesn't exist
-
setConsoleOption
public void setConsoleOption(java.lang.String name, java.lang.Object value)Description copied from interface:SystemRegistrySets the value of a console option.This method sets the value of the console option with the specified name. Console options are used to configure the behavior of the console and its components.
- Specified by:
setConsoleOptionin interfaceSystemRegistry- Parameters:
name- the name of the option to setvalue- the value to assign to the option
-
register
public void register(java.lang.String command, CommandRegistry subcommandRegistry)Register subcommand registry- Specified by:
registerin interfaceSystemRegistry- Parameters:
command- main commandsubcommandRegistry- subcommand registry
-
commandInfo
public java.util.List<java.lang.String> commandInfo(java.lang.String command)
Description copied from interface:CommandRegistryReturns a short info about command known by this registry.- Specified by:
commandInfoin interfaceCommandRegistry- Parameters:
command- the command name- Returns:
- a short info about command
-
hasCommand
public boolean hasCommand(java.lang.String command)
Description copied from interface:CommandRegistryReturns whether a command with the specified name is known to this registry.- Specified by:
hasCommandin interfaceCommandRegistry- Parameters:
command- the command name to test- Returns:
- true if the specified command is registered
-
setGroupCommandsInHelp
public void setGroupCommandsInHelp(boolean commandGroups)
-
groupCommandsInHelp
public SystemRegistryImpl groupCommandsInHelp(boolean commandGroups)
-
isCommandOrScript
public boolean isCommandOrScript(ParsedLine line)
Description copied from interface:SystemRegistryChecks if a parsed line contains a command or script that is known to this registry.This method determines whether the specified parsed command line contains a command or script that is known to this registry. This can be used to determine whether the line can be executed by this registry.
- Specified by:
isCommandOrScriptin interfaceSystemRegistry- Parameters:
line- the parsed command line to test- Returns:
- true if the specified line contains a command or script that is known to this registry, false otherwise
-
isCommandOrScript
public boolean isCommandOrScript(java.lang.String command)
Description copied from interface:SystemRegistryChecks if a command or script is known to this registry.This method determines whether the specified command or script is known to this registry. This can be used to determine whether the command or script can be executed by this registry.
- Specified by:
isCommandOrScriptin interfaceSystemRegistry- Parameters:
command- the command or script name to test- Returns:
- true if the specified command or script is known to this registry, false otherwise
-
addCompleter
public void addCompleter(Completer completer)
-
compileCompleters
public SystemCompleter compileCompleters()
Description copied from interface:CommandRegistryReturns aSystemCompleterthat can provide detailed completion information for all registered commands.- Specified by:
compileCompletersin interfaceCommandRegistry- Returns:
- a SystemCompleter that can provide command completion for all registered commands
-
completer
public Completer completer()
Description copied from interface:SystemRegistryReturns a command completer that includes console variable and script completion.This method creates a completer that can provide completion for commands, console variables, and scripts. The completer can be used for tab completion in the console.
- Specified by:
completerin interfaceSystemRegistry- Returns:
- a completer for commands, console variables, and scripts
-
commandDescription
public CmdDesc commandDescription(java.util.List<java.lang.String> args)
Description copied from interface:CommandRegistryReturns a command description for use in the JLine Widgets framework. Default method must be overridden to return sub command descriptions.- Specified by:
commandDescriptionin interfaceCommandRegistry- Parameters:
args- command (args[0]) and its arguments- Returns:
- command description for JLine TailTipWidgets to be displayed in the terminal status bar.
-
setScriptDescription
public void setScriptDescription(java.util.function.Function<CmdLine,CmdDesc> scriptDescription)
-
commandDescription
public CmdDesc commandDescription(CmdLine line)
Description copied from interface:SystemRegistryReturns a description for a command, method, or syntax for use in the JLine Widgets framework.This method generates a description for the specified command line, which can be displayed in the terminal status bar by JLine TailTipWidgets. The description includes information about the command's arguments, options, and usage.
- Specified by:
commandDescriptionin interfaceSystemRegistry- Parameters:
line- the command line whose description to return- Returns:
- a command description for JLine TailTipWidgets to be displayed in the terminal status bar
-
invoke
public java.lang.Object invoke(java.lang.String command, java.lang.Object... args) throws java.lang.ExceptionDescription copied from interface:SystemRegistryExecutes a command with the specified arguments.This method executes the specified command with the specified arguments. The command is looked up in the command registries associated with this system registry.
- Specified by:
invokein interfaceSystemRegistry- Parameters:
command- the command to be executedargs- the arguments to pass to the command- Returns:
- the result of executing the command
- Throws:
java.lang.Exception- if an error occurs during execution
-
terminal
public Terminal terminal()
Description copied from interface:SystemRegistryReturns the terminal associated with this system registry.This method retrieves the terminal that is used by this system registry for input and output operations.
- Specified by:
terminalin interfaceSystemRegistry- Returns:
- the terminal associated with this system registry
-
isCommandAlias
public boolean isCommandAlias(java.lang.String command)
Description copied from interface:SystemRegistryChecks if an alias is a known command alias.This method determines whether the specified alias is a known command alias. Command aliases are alternative names for commands that can be used to invoke them.
- Specified by:
isCommandAliasin interfaceSystemRegistry- Parameters:
command- the alias to test- Returns:
- true if the specified alias is a known command alias, false otherwise
-
execute
public java.lang.Object execute(java.lang.String line) throws java.lang.ExceptionDescription copied from interface:SystemRegistryExecutes a command, script, or evaluates a script engine statement.This method parses and executes the specified command line. If the line contains a known command, it will be executed. If it contains a script name, the script will be executed. Otherwise, the line will be evaluated as a script engine statement.
- Specified by:
executein interfaceSystemRegistry- Parameters:
line- the command line to be executed- Returns:
- the result of executing the command line
- Throws:
java.lang.Exception- if an error occurs during execution
-
cleanUp
public void cleanUp()
Description copied from interface:SystemRegistryDeletes temporary console variables and resets output streams.This method cleans up temporary console variables and resets output streams to their default state. It should be called after command execution to ensure that temporary variables and redirected output streams don't affect subsequent commands.
- Specified by:
cleanUpin interfaceSystemRegistry
-
trace
public void trace(java.lang.Throwable exception)
Description copied from interface:SystemRegistryPrints an exception on the terminal.This method prints the specified exception on the terminal, including its message and stack trace. This is a convenience method that calls
SystemRegistry.trace(boolean, Throwable)with stack=true.- Specified by:
tracein interfaceSystemRegistry- Parameters:
exception- the exception to print on the terminal
-
trace
public void trace(boolean stack, java.lang.Throwable exception)Description copied from interface:SystemRegistryPrints an exception on the terminal with control over stack trace display.This method prints the specified exception on the terminal. If stack is true, the full stack trace will be printed. Otherwise, only the exception message will be printed.
- Specified by:
tracein interfaceSystemRegistry- Parameters:
stack- whether to print the full stack trace (true) or just the message (false)exception- the exception to be printed
-
close
public void close()
Description copied from interface:SystemRegistryOrderly closes this system registry.This method performs an orderly shutdown of this system registry, releasing any resources it holds and performing any necessary cleanup operations. It should be called when the system registry is no longer needed.
- Specified by:
closein interfaceSystemRegistry
-
consoleEngine
public ConsoleEngine consoleEngine()
-
-