Package org.jline.console.impl
Class SystemRegistryImpl
- java.lang.Object
-
- org.jline.console.impl.SystemRegistryImpl
-
- All Implemented Interfaces:
org.jline.builtins.ConsoleOptionGetter
,CommandRegistry
,SystemRegistry
- Direct Known Subclasses:
SimpleSystemRegistryImpl
public class SystemRegistryImpl extends java.lang.Object implements SystemRegistry
Aggregate command registries.- Author:
- Matti Rinta-Nikkola
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
SystemRegistryImpl.CommandData
static class
SystemRegistryImpl.Pipe
static class
SystemRegistryImpl.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 org.jline.builtins.ConfigurationPath
configPath
protected org.jline.reader.Parser
parser
protected java.util.function.Supplier<java.nio.file.Path>
workDir
-
Constructor Summary
Constructors Constructor Description SystemRegistryImpl(org.jline.reader.Parser parser, org.jline.terminal.Terminal terminal, java.util.function.Supplier<java.nio.file.Path> workDir, org.jline.builtins.ConfigurationPath configPath)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCompleter(org.jline.reader.Completer completer)
void
cleanUp()
Delete temporary console variables and reset output streamsvoid
close()
Orderly close SystemRegistry.java.util.Map<java.lang.String,java.lang.String>
commandAliases()
Returns a map of alias-to-command names known by this registry.CmdDesc
commandDescription(java.util.List<java.lang.String> args)
Returns a command description for use in the JLine Widgets framework.CmdDesc
commandDescription(CmdLine line)
Returns a command, method or syntax description 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.org.jline.reader.impl.completer.SystemCompleter
compileCompleters()
Returns aSystemCompleter
that can provide detailed completion information for all registered commands.org.jline.reader.Completer
completer()
Returns command completer that includes also console variable and script completion.ConsoleEngine
consoleEngine()
java.lang.Object
consoleOption(java.lang.String name)
Return console option value<T> T
consoleOption(java.lang.String name, T defVal)
Return console option valuejava.lang.Object
execute(java.lang.String line)
Execute a command, script or evaluate scriptEngine statementjava.util.Collection<java.lang.String>
getPipeNames()
SystemRegistryImpl
groupCommandsInHelp(boolean commandGroups)
boolean
hasCommand(java.lang.String command)
Returns whether a command with the specified name is known to this registry.void
initialize(java.io.File script)
Initialize consoleEngine environment by executing console scriptjava.lang.Object
invoke(java.lang.String command, java.lang.Object... args)
Execute command with argumentsboolean
isCommandAlias(java.lang.String command)
Returns whether alias is known command alias.boolean
isCommandOrScript(java.lang.String command)
Returns whether command is known to this registry.boolean
isCommandOrScript(org.jline.reader.ParsedLine line)
Returns whether a line contains command/script that is known to this registry.void
register(java.lang.String command, CommandRegistry subcommandRegistry)
Register subcommand registryvoid
rename(SystemRegistryImpl.Pipe pipe, java.lang.String name)
void
setCommandRegistries(CommandRegistry... commandRegistries)
Set command registriesvoid
setConsoleOption(java.lang.String name, java.lang.Object value)
Set console option valuevoid
setGroupCommandsInHelp(boolean commandGroups)
void
setScriptDescription(java.util.function.Function<CmdLine,CmdDesc> scriptDescription)
org.jline.terminal.Terminal
terminal()
void
trace(boolean stack, java.lang.Throwable exception)
Print exception on terminalvoid
trace(java.lang.Throwable exception)
Print exception on 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
-
-
-
-
Method Detail
-
rename
public void rename(SystemRegistryImpl.Pipe pipe, java.lang.String name)
-
getPipeNames
public java.util.Collection<java.lang.String> getPipeNames()
- Specified by:
getPipeNames
in interfaceSystemRegistry
- Returns:
- pipe names defined in systemRegistry
-
setCommandRegistries
public void setCommandRegistries(CommandRegistry... commandRegistries)
Description copied from interface:SystemRegistry
Set command registries- Specified by:
setCommandRegistries
in interfaceSystemRegistry
- Parameters:
commandRegistries
- command registries used by the application
-
initialize
public void initialize(java.io.File script)
Description copied from interface:SystemRegistry
Initialize consoleEngine environment by executing console script- Specified by:
initialize
in interfaceSystemRegistry
- Parameters:
script
- initialization script
-
commandNames
public java.util.Set<java.lang.String> commandNames()
Description copied from interface:CommandRegistry
Returns the command names known by this registry.- Specified by:
commandNames
in 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:CommandRegistry
Returns a map of alias-to-command names known by this registry.- Specified by:
commandAliases
in 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:SystemRegistry
Return console option value- Specified by:
consoleOption
in interfaceorg.jline.builtins.ConsoleOptionGetter
- Specified by:
consoleOption
in interfaceSystemRegistry
- Parameters:
name
- the option name- Returns:
- option value
-
consoleOption
public <T> T consoleOption(java.lang.String name, T defVal)
Description copied from interface:SystemRegistry
Return console option value- Specified by:
consoleOption
in interfaceorg.jline.builtins.ConsoleOptionGetter
- Specified by:
consoleOption
in interfaceSystemRegistry
- Parameters:
name
- the option namedefVal
- value to return if console option does not exists- Returns:
- option value
-
setConsoleOption
public void setConsoleOption(java.lang.String name, java.lang.Object value)
Description copied from interface:SystemRegistry
Set console option value- Specified by:
setConsoleOption
in interfaceSystemRegistry
- Parameters:
name
- the option namevalue
- value to assign console option
-
register
public void register(java.lang.String command, CommandRegistry subcommandRegistry)
Register subcommand registry- Specified by:
register
in interfaceSystemRegistry
- Parameters:
command
- main commandsubcommandRegistry
- subcommand registry
-
commandInfo
public java.util.List<java.lang.String> commandInfo(java.lang.String command)
Description copied from interface:CommandRegistry
Returns a short info about command known by this registry.- Specified by:
commandInfo
in interfaceCommandRegistry
- Parameters:
command
- the command name- Returns:
- a short info about command
-
hasCommand
public boolean hasCommand(java.lang.String command)
Description copied from interface:CommandRegistry
Returns whether a command with the specified name is known to this registry.- Specified by:
hasCommand
in 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(org.jline.reader.ParsedLine line)
Description copied from interface:SystemRegistry
Returns whether a line contains command/script that is known to this registry.- Specified by:
isCommandOrScript
in interfaceSystemRegistry
- Parameters:
line
- the parsed command line to test- Returns:
- true if the specified line has a command registered
-
isCommandOrScript
public boolean isCommandOrScript(java.lang.String command)
Description copied from interface:SystemRegistry
Returns whether command is known to this registry.- Specified by:
isCommandOrScript
in interfaceSystemRegistry
- Parameters:
command
- the command to test- Returns:
- true if the specified command is known
-
addCompleter
public void addCompleter(org.jline.reader.Completer completer)
-
compileCompleters
public org.jline.reader.impl.completer.SystemCompleter compileCompleters()
Description copied from interface:CommandRegistry
Returns aSystemCompleter
that can provide detailed completion information for all registered commands.- Specified by:
compileCompleters
in interfaceCommandRegistry
- Returns:
- a SystemCompleter that can provide command completion for all registered commands
-
completer
public org.jline.reader.Completer completer()
Description copied from interface:SystemRegistry
Returns command completer that includes also console variable and script completion.- Specified by:
completer
in interfaceSystemRegistry
- Returns:
- command completer
-
commandDescription
public CmdDesc commandDescription(java.util.List<java.lang.String> args)
Description copied from interface:CommandRegistry
Returns a command description for use in the JLine Widgets framework. Default method must be overridden to return sub command descriptions.- Specified by:
commandDescription
in 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:SystemRegistry
Returns a command, method or syntax description for use in the JLine Widgets framework.- Specified by:
commandDescription
in interfaceSystemRegistry
- Parameters:
line
- command line whose description to return- Returns:
- 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.Exception
Description copied from interface:SystemRegistry
Execute command with arguments- Specified by:
invoke
in interfaceSystemRegistry
- Parameters:
command
- command to be executedargs
- arguments of the command- Returns:
- command execution result
- Throws:
java.lang.Exception
- in case of error
-
terminal
public org.jline.terminal.Terminal terminal()
- Specified by:
terminal
in interfaceSystemRegistry
- Returns:
- terminal
-
isCommandAlias
public boolean isCommandAlias(java.lang.String command)
Description copied from interface:SystemRegistry
Returns whether alias is known command alias.- Specified by:
isCommandAlias
in interfaceSystemRegistry
- Parameters:
command
- the alias to test- Returns:
- true if the alias is known command alias
-
execute
public java.lang.Object execute(java.lang.String line) throws java.lang.Exception
Description copied from interface:SystemRegistry
Execute a command, script or evaluate scriptEngine statement- Specified by:
execute
in interfaceSystemRegistry
- Parameters:
line
- command line to be executed- Returns:
- execution result
- Throws:
java.lang.Exception
- in case of error
-
cleanUp
public void cleanUp()
Description copied from interface:SystemRegistry
Delete temporary console variables and reset output streams- Specified by:
cleanUp
in interfaceSystemRegistry
-
trace
public void trace(java.lang.Throwable exception)
Description copied from interface:SystemRegistry
Print exception on terminal- Specified by:
trace
in interfaceSystemRegistry
- Parameters:
exception
- exception to print on terminal
-
trace
public void trace(boolean stack, java.lang.Throwable exception)
Description copied from interface:SystemRegistry
Print exception on terminal- Specified by:
trace
in interfaceSystemRegistry
- Parameters:
stack
- print stack trace if stack true otherwise messageexception
- exception to be printed
-
close
public void close()
Description copied from interface:SystemRegistry
Orderly close SystemRegistry.- Specified by:
close
in interfaceSystemRegistry
-
consoleEngine
public ConsoleEngine consoleEngine()
-
-