public class ConsoleEngineImpl extends Object implements ConsoleEngine
| Modifier and Type | Class and Description |
|---|---|
static class |
ConsoleEngineImpl.Command |
ConsoleEngine.ExecutionResult, ConsoleEngine.WidgetCreatorCommandRegistry.CommandSession| Constructor and Description |
|---|
ConsoleEngineImpl(ScriptEngine engine,
Supplier<Path> workDir,
ConfigurationPath configPath) |
| Modifier and Type | Method and 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<org.jline.utils.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(Map<String,Object> options,
Object object)
Print object.
|
void |
println(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,org.jline.utils.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, waitexecute, plainCommandaggregateCompleters, commandDescription, commandInfo, compileCompleters, execute, namepublic ConsoleEngineImpl(ScriptEngine engine, Supplier<Path> workDir, ConfigurationPath configPath) throws IOException
IOExceptionpublic 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,org.jline.utils.AttributedString>> highlightValue)
highlightValue - key: regex for column name, value: highlight functionpublic void setLineReader(LineReader reader)
ConsoleEnginesetLineReader in interface ConsoleEnginereader - LineReaderpublic boolean isExecuting()
isExecuting in interface ConsoleEnginepublic void setSystemRegistry(SystemRegistry systemRegistry)
ConsoleEnginesetSystemRegistry in interface ConsoleEnginesystemRegistry - SystemRegistrypublic void setScriptExtension(String extension)
ConsoleEnginesetScriptExtension in interface ConsoleEngineextension - console script file extensionpublic Set<String> commandNames()
CommandRegistrycommandNames in interface CommandRegistrypublic Map<String,String> commandAliases()
CommandRegistrycommandAliases in interface CommandRegistrypublic boolean hasCommand(String name)
CommandRegistryhasCommand in interface CommandRegistryname - the command name to testpublic boolean hasAlias(String name)
ConsoleEnginehasAlias in interface ConsoleEnginename - alias namepublic String getAlias(String name)
ConsoleEnginegetAlias in interface ConsoleEnginename - alias namepublic Map<String,List<String>> getPipes()
ConsoleEnginegetPipes in interface ConsoleEnginepublic List<String> getNamedPipes()
ConsoleEnginegetNamedPipes in interface ConsoleEnginepublic void rename(ConsoleEngineImpl.Command command, String newName)
public Completers.SystemCompleter compileCompleters()
CommandRegistrySystemCompleter that can provide detailed completion
information for all registered commands.compileCompleters in interface CommandRegistrypublic List<Completer> scriptCompleters()
ConsoleEnginescriptCompleters in interface ConsoleEnginepublic Map<String,Boolean> scripts()
ConsoleEnginescripts in interface ConsoleEnginepublic Object[] expandParameters(String[] args) throws Exception
ConsoleEngineexpandParameters in interface ConsoleEngineargs - the arguments to be expandedException - in case of errorpublic String expandToList(List<String> params)
ConsoleEngineexpandToList in interface ConsoleEngineparams - list of script parameterspublic Object execute(File script, String cmdLine, String[] args) throws Exception
ConsoleEngineexecute in interface ConsoleEnginescript - script filecmdLine - raw command lineargs - script argumentsException - in case of errorpublic String expandCommandLine(String line)
ConsoleEngineexpandCommandLine in interface ConsoleEngineline - command line to be expandedpublic Object execute(String cmd, String line, String[] args) throws Exception
ConsoleEngineexecute in interface ConsoleEnginecmd - parsed command/script nameline - raw command lineargs - parsed arguments of the commandException - in case of errorpublic void purge()
ConsoleEnginepurge in interface ConsoleEnginepublic void putVariable(String name, Object value)
ConsoleEngineputVariable in interface ConsoleEnginename - name of the variablevalue - value of the variablepublic Object getVariable(String name)
ConsoleEnginegetVariable in interface ConsoleEnginename - name of the variablepublic boolean hasVariable(String name)
ConsoleEnginehasVariable in interface ConsoleEnginename - name of the variablepublic boolean executeWidget(Object function)
ConsoleEngineexecuteWidget in interface ConsoleEnginefunction - to executepublic <T> T consoleOption(String option, T defval)
ConsoleEngineconsoleOption in interface ConsoleEngineT - option typeoption - option namedefval - default valuepublic ConsoleEngine.ExecutionResult postProcess(String line, Object result, String output)
ConsoleEnginepostProcess in interface ConsoleEngineline - command lineresult - command result to processoutput - command redirected outputpublic ConsoleEngine.ExecutionResult postProcess(Object result)
ConsoleEnginepostProcess in interface ConsoleEngineresult - command result to processpublic Object invoke(CommandRegistry.CommandSession session, String command, Object... args) throws Exception
CommandRegistryinvoke in interface CommandRegistrysession - 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 ConsoleEngineobject - object to printpublic void println(Object object)
ConsoleEngineprintln in interface ConsoleEngineobject - object to printpublic void println(Map<String,Object> options, Object object)
ConsoleEngineprintln in interface ConsoleEngineoptions - println optionsobject - object to printpublic List<org.jline.utils.AttributedString> highlightList(Map<String,Object> options, List<Object> collection, int width)
public void persist(Path file, Object object)
ConsoleEnginepersist in interface ConsoleEnginefile - file where object should be writtenobject - object to persistpublic Object slurp(Path file) throws IOException
ConsoleEngineslurp in interface ConsoleEnginefile - file from where object should be readIOExceptionCopyright © 2020. All rights reserved.