CommandRegistry
, ConsoleEngine
public class ConsoleEngineImpl extends Object implements ConsoleEngine
Modifier and Type | Class | Description |
---|---|---|
static class |
ConsoleEngineImpl.Command |
CommandRegistry.CommandSession
ConsoleEngine.ExecutionResult, ConsoleEngine.WidgetCreator
Constructor | Description |
---|---|
ConsoleEngineImpl(ScriptEngine engine,
Supplier<Path> workDir,
ConfigurationPath configPath) |
Modifier and Type | Method | Description |
---|---|---|
void |
alias(String alias,
String command) |
|
Map<String,String> |
commandAliases() |
Returns a map of alias-to-command names known by this registry.
|
Set<String> |
commandNames() |
Returns the command names known by this registry.
|
Completers.SystemCompleter |
compileCompleters() |
Returns a
SystemCompleter that can provide detailed completion
information for all registered commands. |
<T> T |
consoleOption(String option,
T defval) |
Read console option value
|
Object |
execute(File script,
String cmdLine,
String[] args) |
Executes either JLine or ScriptEngine script.
|
Object |
execute(String cmd,
String line,
String[] args) |
Executes command line that does not contain known command by the system registry.
|
boolean |
executeWidget(Object function) |
Execute widget function
|
String |
expandCommandLine(String line) |
Substitutes command line with system registry invoke method call.
|
Object[] |
expandParameters(String[] args) |
Substituting args references with their values.
|
String |
expandToList(List<String> params) |
Expands parameter list to string
|
String |
getAlias(String name) |
Returns alias 'name' value
|
List<String> |
getNamedPipes() |
Returns named pipe names
|
Map<String,List<String>> |
getPipes() |
Returns defined pipes
|
Object |
getVariable(String name) |
Get variable value
|
boolean |
hasAlias(String name) |
Returns true if alias 'name' exists
|
boolean |
hasCommand(String name) |
Returns whether a command with the specified name is known to this registry.
|
boolean |
hasVariable(String name) |
Test if variable with name exists
|
List<AttributedString> |
highlightList(Map<String,Object> options,
List<Object> collection,
int width) |
|
Object |
invoke(CommandRegistry.CommandSession session,
String command,
Object... args) |
Execute a command.
|
boolean |
isExecuting() |
|
void |
persist(Path file,
Object object) |
Persist object to file
|
ConsoleEngine.ExecutionResult |
postProcess(Object result) |
Post processes execution result.
|
ConsoleEngine.ExecutionResult |
postProcess(String line,
Object result,
String output) |
Post processes execution result.
|
void |
println(Object object) |
Print object.
|
void |
println(Map<String,Object> options,
Object object) |
Print object.
|
void |
purge() |
Delete temporary console variables
|
void |
putVariable(String name,
Object value) |
Create console variable
|
void |
rename(ConsoleEngineImpl.Command command,
String newName) |
|
List<Completer> |
scriptCompleters() |
Returns script and variable completers
|
Map<String,Boolean> |
scripts() |
Returns all scripts found from PATH
|
void |
setHighlightValue(Map<String,Function<Object,AttributedString>> highlightValue) |
Highlight column value
|
void |
setLineReader(LineReader reader) |
Sets lineReader
|
void |
setObjectToMap(Map<Class<?>,Function<Object,Map<String,Object>>> objectToMap) |
Override ScriptEngine toMap() method
|
void |
setObjectToString(Map<Class<?>,Function<Object,String>> objectToString) |
Override ScriptEngine toString() method
|
void |
setScriptExtension(String extension) |
Sets file name extension used by console scripts
|
void |
setSystemRegistry(SystemRegistry systemRegistry) |
Sets systemRegistry
|
Object |
slurp(Path file) |
Read object from file
|
void |
trace(Object object) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
commandDescription, commandInfo, execute, name
execute
public ConsoleEngineImpl(ScriptEngine engine, Supplier<Path> workDir, ConfigurationPath configPath) throws IOException
IOException
public void setObjectToMap(Map<Class<?>,Function<Object,Map<String,Object>>> objectToMap)
objectToMap
- key: object class, value: toMap functionpublic void setObjectToString(Map<Class<?>,Function<Object,String>> objectToString)
objectToString
- key: object class, value: toString functionpublic void setHighlightValue(Map<String,Function<Object,AttributedString>> highlightValue)
highlightValue
- key: regex for column name, value: highlight functionpublic void setLineReader(LineReader reader)
ConsoleEngine
setLineReader
in interface ConsoleEngine
reader
- LineReaderpublic boolean isExecuting()
isExecuting
in interface ConsoleEngine
public void setSystemRegistry(SystemRegistry systemRegistry)
ConsoleEngine
setSystemRegistry
in interface ConsoleEngine
systemRegistry
- SystemRegistrypublic void setScriptExtension(String extension)
ConsoleEngine
setScriptExtension
in interface ConsoleEngine
extension
- console script file extensionpublic Set<String> commandNames()
CommandRegistry
commandNames
in interface CommandRegistry
public Map<String,String> commandAliases()
CommandRegistry
commandAliases
in interface CommandRegistry
public boolean hasCommand(String name)
CommandRegistry
hasCommand
in interface CommandRegistry
name
- the command name to testpublic boolean hasAlias(String name)
ConsoleEngine
hasAlias
in interface ConsoleEngine
name
- alias namepublic String getAlias(String name)
ConsoleEngine
getAlias
in interface ConsoleEngine
name
- alias namepublic Map<String,List<String>> getPipes()
ConsoleEngine
getPipes
in interface ConsoleEngine
public List<String> getNamedPipes()
ConsoleEngine
getNamedPipes
in interface ConsoleEngine
public void rename(ConsoleEngineImpl.Command command, String newName)
public Completers.SystemCompleter compileCompleters()
CommandRegistry
SystemCompleter
that can provide detailed completion
information for all registered commands.compileCompleters
in interface CommandRegistry
public List<Completer> scriptCompleters()
ConsoleEngine
scriptCompleters
in interface ConsoleEngine
public Map<String,Boolean> scripts()
ConsoleEngine
scripts
in interface ConsoleEngine
public Object[] expandParameters(String[] args) throws Exception
ConsoleEngine
expandParameters
in interface ConsoleEngine
args
- the arguments to be expandedException
- in case of errorpublic String expandToList(List<String> params)
ConsoleEngine
expandToList
in interface ConsoleEngine
params
- list of script parameterspublic Object execute(File script, String cmdLine, String[] args) throws Exception
ConsoleEngine
execute
in interface ConsoleEngine
script
- script filecmdLine
- raw command lineargs
- script argumentsException
- in case of errorpublic String expandCommandLine(String line)
ConsoleEngine
expandCommandLine
in interface ConsoleEngine
line
- command line to be expandedpublic Object execute(String cmd, String line, String[] args) throws Exception
ConsoleEngine
execute
in interface ConsoleEngine
cmd
- parsed command/script nameline
- raw command lineargs
- parsed arguments of the commandException
- in case of errorpublic void purge()
ConsoleEngine
purge
in interface ConsoleEngine
public void putVariable(String name, Object value)
ConsoleEngine
putVariable
in interface ConsoleEngine
name
- name of the variablevalue
- value of the variablepublic Object getVariable(String name)
ConsoleEngine
getVariable
in interface ConsoleEngine
name
- name of the variablepublic boolean hasVariable(String name)
ConsoleEngine
hasVariable
in interface ConsoleEngine
name
- name of the variablepublic boolean executeWidget(Object function)
ConsoleEngine
executeWidget
in interface ConsoleEngine
function
- to executepublic <T> T consoleOption(String option, T defval)
ConsoleEngine
consoleOption
in interface ConsoleEngine
T
- option typeoption
- option namedefval
- default valuepublic ConsoleEngine.ExecutionResult postProcess(String line, Object result, String output)
ConsoleEngine
postProcess
in interface ConsoleEngine
line
- command lineresult
- command result to processoutput
- command redirected outputpublic ConsoleEngine.ExecutionResult postProcess(Object result)
ConsoleEngine
postProcess
in interface ConsoleEngine
result
- command result to processpublic Object invoke(CommandRegistry.CommandSession session, String command, Object... args) throws Exception
CommandRegistry
invoke
in interface CommandRegistry
session
- the data of the current command sessioncommand
- the name of the commandargs
- arguments of the commandException
- in case of errorpublic void trace(Object object)
trace
in interface ConsoleEngine
object
- object to printpublic void println(Object object)
ConsoleEngine
println
in interface ConsoleEngine
object
- object to printpublic void println(Map<String,Object> options, Object object)
ConsoleEngine
println
in interface ConsoleEngine
options
- println optionsobject
- object to printpublic List<AttributedString> highlightList(Map<String,Object> options, List<Object> collection, int width)
public void persist(Path file, Object object)
ConsoleEngine
persist
in interface ConsoleEngine
file
- file where object should be writtenobject
- object to persistpublic Object slurp(Path file) throws IOException
ConsoleEngine
slurp
in interface ConsoleEngine
file
- file from where object should be readIOException
Copyright © 2020. All rights reserved.