Package org.jline.console.impl
Class SystemRegistryImpl
- java.lang.Object
-
- org.jline.console.impl.SystemRegistryImpl
-
- All Implemented Interfaces:
ConsoleOptionGetter
,CommandRegistry
,SystemRegistry
public class SystemRegistryImpl extends java.lang.Object implements SystemRegistry
Aggregate command registries.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SystemRegistryImpl.ArgsParser
protected static class
SystemRegistryImpl.CommandData
private static class
SystemRegistryImpl.CommandOutputStream
private class
SystemRegistryImpl.NamesAndValues
static class
SystemRegistryImpl.Pipe
private static class
SystemRegistryImpl.PipelineCompleter
private static class
SystemRegistryImpl.ScriptStore
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 private static java.lang.Class<?>[]
BUILTIN_REGISTRIES
private java.util.Map<java.lang.String,CommandMethods>
commandExecute
private boolean
commandGroups
private java.util.Map<java.lang.String,java.util.List<java.lang.String>>
commandInfos
private CommandRegistry[]
commandRegistries
protected ConfigurationPath
configPath
private java.lang.Integer
consoleId
private AggregateCompleter
customAggregateCompleter
private SystemCompleter
customSystemCompleter
private java.lang.Exception
exception
private SystemRegistryImpl.NamesAndValues
names
private SystemRegistryImpl.CommandOutputStream
outputStream
protected Parser
parser
private java.util.Map<SystemRegistryImpl.Pipe,java.lang.String>
pipeName
private java.util.function.Function<CmdLine,CmdDesc>
scriptDescription
private SystemRegistryImpl.ScriptStore
scriptStore
private java.util.Map<java.lang.String,CommandRegistry>
subcommands
protected 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 private SystemCompleter
_compileCompleters()
void
addCompleter(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.private CmdDesc
commandDescription(CommandRegistry subreg)
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.private java.util.List<Completers.OptDesc>
commandOptions(java.lang.String command)
private CommandRegistry.CommandSession
commandSession()
private java.util.List<SystemRegistryImpl.CommandData>
compileCommandLine(java.lang.String commandLine)
SystemCompleter
compileCompleters()
Returns aSystemCompleter
that can provide detailed completion information for all registered commands.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 valueprivate java.lang.String
doCommandInfo(java.util.List<java.lang.String> info)
private java.util.List<Completer>
emptyCompleter(java.lang.String command)
java.lang.Object
execute(java.lang.String line)
Execute a command, script or evaluate scriptEngine statementprivate java.lang.Object
execute(java.lang.String command, java.lang.String rawLine, java.lang.String[] args)
private java.lang.Object
exit(CommandInput input)
private java.util.List<Completer>
exitCompleter(java.lang.String command)
private java.lang.String
flipArgument(java.lang.String command, java.lang.String subLine, java.util.List<java.lang.String> pipes, java.util.List<java.lang.String> arglist)
java.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.private java.lang.Object
help(CommandInput input)
private java.util.List<Completer>
helpCompleter(java.lang.String command)
private void
helpTopic(java.util.List<java.lang.String> topics, boolean commandGroups, boolean info)
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 argumentsprivate boolean
isBuiltinRegistry(CommandRegistry registry)
boolean
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(ParsedLine line)
Returns whether a line contains command/script that is known to this registry.private boolean
isInTopics(java.util.List<java.lang.String> args, java.lang.String name)
private boolean
isLocalCommand(java.lang.String command)
private CmdDesc
localCommandDescription(java.lang.String command)
private java.util.List<java.lang.String>
localCommandInfo(java.lang.String command)
private java.util.Set<java.lang.String>
localCommandNames()
private java.lang.Object
localExecute(java.lang.String command, java.lang.Object[] args)
private Options
parseOptions(java.lang.String[] usage, java.lang.Object[] args)
private ConsoleEngine.ExecutionResult
postProcess(SystemRegistryImpl.CommandData cmd, boolean statement, ConsoleEngine consoleEngine, java.lang.Object result)
private void
printCommandInfo(java.lang.String command, java.lang.String info, int max)
private void
printCommands(java.util.Collection<java.lang.String> commands, int max)
private void
printHeader(java.lang.String header)
private java.io.File
redirectFile(java.lang.String name)
void
register(java.lang.String command, CommandRegistry subcommandRegistry)
Register subcommand registryprivate void
registryHelp(CommandRegistry registry)
private int
registryId(java.lang.String command)
private java.util.List<java.lang.String>
registryNames()
void
rename(SystemRegistryImpl.Pipe pipe, java.lang.String name)
private java.lang.String
replaceCommandAlias(java.lang.String variable, java.lang.String command, java.lang.String rawLine)
private java.lang.String
replacePipeAlias(SystemRegistryImpl.ArgsParser ap, java.lang.String pipeAlias, java.util.List<java.lang.String> args, java.util.Map<java.lang.String,java.util.List<java.lang.String>> customPipes)
private void
replacePipeAliases(ConsoleEngine consoleEngine, java.util.Map<java.lang.String,java.util.List<java.lang.String>> customPipes, SystemRegistryImpl.ArgsParser ap)
void
setCommandRegistries(CommandRegistry... commandRegistries)
Set command registriesvoid
setGroupCommandsInHelp(boolean commandGroups)
void
setScriptDescription(java.util.function.Function<CmdLine,CmdDesc> scriptDescription)
private java.lang.Object
subcommand(CommandInput input)
Terminal
terminal()
void
trace(boolean stack, java.lang.Throwable exception)
Print exception on terminalvoid
trace(java.lang.Throwable exception)
Print exception on terminalprivate void
trace(SystemRegistryImpl.CommandData commandData)
-
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
-
BUILTIN_REGISTRIES
private static final java.lang.Class<?>[] BUILTIN_REGISTRIES
-
commandRegistries
private CommandRegistry[] commandRegistries
-
consoleId
private java.lang.Integer consoleId
-
parser
protected final Parser parser
-
configPath
protected final ConfigurationPath configPath
-
workDir
protected final java.util.function.Supplier<java.nio.file.Path> workDir
-
subcommands
private final java.util.Map<java.lang.String,CommandRegistry> subcommands
-
pipeName
private final java.util.Map<SystemRegistryImpl.Pipe,java.lang.String> pipeName
-
commandExecute
private final java.util.Map<java.lang.String,CommandMethods> commandExecute
-
commandInfos
private final java.util.Map<java.lang.String,java.util.List<java.lang.String>> commandInfos
-
exception
private java.lang.Exception exception
-
outputStream
private final SystemRegistryImpl.CommandOutputStream outputStream
-
scriptStore
private SystemRegistryImpl.ScriptStore scriptStore
-
names
private SystemRegistryImpl.NamesAndValues names
-
customSystemCompleter
private final SystemCompleter customSystemCompleter
-
customAggregateCompleter
private final AggregateCompleter customAggregateCompleter
-
commandGroups
private boolean commandGroups
-
-
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)
-
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
-
localCommandNames
private java.util.Set<java.lang.String> localCommandNames()
-
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 interfaceConsoleOptionGetter
- Specified by:
consoleOption
in interfaceSystemRegistry
- Parameters:
name
- the option name- Returns:
- option value
-
register
public void register(java.lang.String command, CommandRegistry subcommandRegistry)
Register subcommand registry- Specified by:
register
in interfaceSystemRegistry
- Parameters:
command
- main commandsubcommandRegistry
- subcommand registry
-
localCommandInfo
private java.util.List<java.lang.String> localCommandInfo(java.lang.String command)
-
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)
-
isLocalCommand
private boolean isLocalCommand(java.lang.String command)
-
isCommandOrScript
public boolean isCommandOrScript(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(Completer completer)
-
compileCompleters
public 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
-
_compileCompleters
private SystemCompleter _compileCompleters()
-
completer
public 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
-
localCommandDescription
private CmdDesc localCommandDescription(java.lang.String command)
-
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.
-
commandDescription
private CmdDesc commandDescription(CommandRegistry subreg)
-
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
-
localExecute
private java.lang.Object localExecute(java.lang.String command, java.lang.Object[] args) throws java.lang.Exception
- Throws:
java.lang.Exception
-
terminal
public Terminal terminal()
- Specified by:
terminal
in interfaceSystemRegistry
- Returns:
- terminal
-
commandSession
private CommandRegistry.CommandSession commandSession()
-
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
-
replaceCommandAlias
private java.lang.String replaceCommandAlias(java.lang.String variable, java.lang.String command, java.lang.String rawLine)
-
replacePipeAlias
private java.lang.String replacePipeAlias(SystemRegistryImpl.ArgsParser ap, java.lang.String pipeAlias, java.util.List<java.lang.String> args, java.util.Map<java.lang.String,java.util.List<java.lang.String>> customPipes)
-
replacePipeAliases
private void replacePipeAliases(ConsoleEngine consoleEngine, java.util.Map<java.lang.String,java.util.List<java.lang.String>> customPipes, SystemRegistryImpl.ArgsParser ap)
-
compileCommandLine
private java.util.List<SystemRegistryImpl.CommandData> compileCommandLine(java.lang.String commandLine)
-
redirectFile
private java.io.File redirectFile(java.lang.String name)
-
flipArgument
private java.lang.String flipArgument(java.lang.String command, java.lang.String subLine, java.util.List<java.lang.String> pipes, java.util.List<java.lang.String> arglist)
-
execute
private java.lang.Object execute(java.lang.String command, java.lang.String rawLine, java.lang.String[] args) throws java.lang.Exception
- Throws:
java.lang.Exception
-
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
-
postProcess
private ConsoleEngine.ExecutionResult postProcess(SystemRegistryImpl.CommandData cmd, boolean statement, ConsoleEngine consoleEngine, java.lang.Object result)
-
cleanUp
public void cleanUp()
Description copied from interface:SystemRegistry
Delete temporary console variables and reset output streams- Specified by:
cleanUp
in interfaceSystemRegistry
-
trace
private void trace(SystemRegistryImpl.CommandData commandData)
-
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()
-
isBuiltinRegistry
private boolean isBuiltinRegistry(CommandRegistry registry)
-
printHeader
private void printHeader(java.lang.String header)
-
printCommandInfo
private void printCommandInfo(java.lang.String command, java.lang.String info, int max)
-
printCommands
private void printCommands(java.util.Collection<java.lang.String> commands, int max)
-
doCommandInfo
private java.lang.String doCommandInfo(java.util.List<java.lang.String> info)
-
isInTopics
private boolean isInTopics(java.util.List<java.lang.String> args, java.lang.String name)
-
parseOptions
private Options parseOptions(java.lang.String[] usage, java.lang.Object[] args) throws Options.HelpException
- Throws:
Options.HelpException
-
help
private java.lang.Object help(CommandInput input)
-
helpTopic
private void helpTopic(java.util.List<java.lang.String> topics, boolean commandGroups, boolean info)
-
exit
private java.lang.Object exit(CommandInput input)
-
registryHelp
private void registryHelp(CommandRegistry registry) throws java.lang.Exception
- Throws:
java.lang.Exception
-
subcommand
private java.lang.Object subcommand(CommandInput input)
-
commandOptions
private java.util.List<Completers.OptDesc> commandOptions(java.lang.String command)
-
registryNames
private java.util.List<java.lang.String> registryNames()
-
emptyCompleter
private java.util.List<Completer> emptyCompleter(java.lang.String command)
-
helpCompleter
private java.util.List<Completer> helpCompleter(java.lang.String command)
-
exitCompleter
private java.util.List<Completer> exitCompleter(java.lang.String command)
-
registryId
private int registryId(java.lang.String command)
-
-