- java.lang.Object
-
- org.jline.console.impl.AbstractCommandRegistry
-
- org.jline.console.impl.JlineCommandRegistry
-
- org.jline.console.impl.ConsoleEngineImpl
-
- All Implemented Interfaces:
CommandRegistry,ConsoleEngine
public class ConsoleEngineImpl extends JlineCommandRegistry implements ConsoleEngine
Manage console variables, commands and script execution.- Author:
- Matti Rinta-Nikkola
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConsoleEngineImpl.Command-
Nested classes/interfaces inherited from interface org.jline.console.CommandRegistry
CommandRegistry.CommandSession
-
Nested classes/interfaces inherited from interface org.jline.console.ConsoleEngine
ConsoleEngine.ExecutionResult, ConsoleEngine.WidgetCreator
-
-
Constructor Summary
Constructors Constructor Description ConsoleEngineImpl(Set<ConsoleEngineImpl.Command> commands, ScriptEngine engine, Printer printer, Supplier<Path> workDir, ConfigurationPath configPath)ConsoleEngineImpl(ScriptEngine engine, Printer printer, Supplier<Path> workDir, ConfigurationPath configPath)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TconsoleOption(String option, T defval)Read console option valueObjectexecute(File script, String cmdLine, String[] args)Executes either JLine or ScriptEngine script.Objectexecute(String cmd, String line, String[] args)Executes command line that does not contain known command by the system registry.booleanexecuteWidget(Object function)Execute widget functionStringexpandCommandLine(String line)Substitutes command line with system registry invoke method call.Object[]expandParameters(String[] args)Substituting args references with their values.StringexpandToList(List<String> params)Expands parameter list to stringStringgetAlias(String name)Returns alias 'name' valueList<String>getNamedPipes()Returns named pipe namesMap<String,List<String>>getPipes()Returns defined pipesObjectgetVariable(String name)Get variable valuebooleanhasAlias(String name)Returns true if alias 'name' existsbooleanhasVariable(String name)Test if variable with name existsObjectinvoke(CommandRegistry.CommandSession session, String command, Object... args)Execute a command.booleanisExecuting()voidpersist(Path file, Object object)Persist object to fileConsoleEngine.ExecutionResultpostProcess(Object result)Post processes execution result.ConsoleEngine.ExecutionResultpostProcess(String line, Object result, String output)Post processes execution result.voidprintln(Object object)Print object.voidpurge()Delete temporary console variablesvoidputVariable(String name, Object value)Create console variableList<Completer>scriptCompleters()Returns script and variable completersMap<String,Boolean>scripts()Returns all scripts found from PATHvoidsetLineReader(LineReader reader)Sets lineReadervoidsetScriptExtension(String extension)Sets file name extension used by console scriptsvoidsetSystemRegistry(SystemRegistry systemRegistry)Sets systemRegistryObjectslurp(Path file)Read object from filevoidtrace(Object object)-
Methods inherited from class org.jline.console.impl.JlineCommandRegistry
commandDescription, commandInfo, commandOptions, compileCommandDescription, compileCommandInfo, compileCommandOptions, defaultCompleter, parseOptions
-
Methods inherited from class org.jline.console.impl.AbstractCommandRegistry
alias, commandAliases, commandNames, compileCompleters, doHelpDesc, getCommandMethods, hasCommand, registerCommands, registerCommands, registeredCommand, rename, saveException
-
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
commandAliases, commandDescription, commandInfo, commandNames, compileCompleters, hasCommand, name
-
Methods inherited from interface org.jline.console.ConsoleEngine
execute
-
-
-
-
Constructor Detail
-
ConsoleEngineImpl
public ConsoleEngineImpl(ScriptEngine engine, Printer printer, Supplier<Path> workDir, ConfigurationPath configPath) throws IOException
- Throws:
IOException
-
ConsoleEngineImpl
public ConsoleEngineImpl(Set<ConsoleEngineImpl.Command> commands, ScriptEngine engine, Printer printer, Supplier<Path> workDir, ConfigurationPath configPath) throws IOException
- Throws:
IOException
-
-
Method Detail
-
setLineReader
public void setLineReader(LineReader reader)
Description copied from interface:ConsoleEngineSets lineReader- Specified by:
setLineReaderin interfaceConsoleEngine- Parameters:
reader- LineReader
-
isExecuting
public boolean isExecuting()
- Specified by:
isExecutingin interfaceConsoleEngine- Returns:
- true if consoleEngine is executing script
-
setSystemRegistry
public void setSystemRegistry(SystemRegistry systemRegistry)
Description copied from interface:ConsoleEngineSets systemRegistry- Specified by:
setSystemRegistryin interfaceConsoleEngine- Parameters:
systemRegistry- SystemRegistry
-
setScriptExtension
public void setScriptExtension(String extension)
Description copied from interface:ConsoleEngineSets file name extension used by console scripts- Specified by:
setScriptExtensionin interfaceConsoleEngine- Parameters:
extension- console script file extension
-
hasAlias
public boolean hasAlias(String name)
Description copied from interface:ConsoleEngineReturns true if alias 'name' exists- Specified by:
hasAliasin interfaceConsoleEngine- Parameters:
name- alias name- Returns:
- true if alias exists
-
getAlias
public String getAlias(String name)
Description copied from interface:ConsoleEngineReturns alias 'name' value- Specified by:
getAliasin interfaceConsoleEngine- Parameters:
name- alias name- Returns:
- value of alias
-
getPipes
public Map<String,List<String>> getPipes()
Description copied from interface:ConsoleEngineReturns defined pipes- Specified by:
getPipesin interfaceConsoleEngine- Returns:
- map of defined pipes
-
getNamedPipes
public List<String> getNamedPipes()
Description copied from interface:ConsoleEngineReturns named pipe names- Specified by:
getNamedPipesin interfaceConsoleEngine- Returns:
- list of named pipe names
-
scriptCompleters
public List<Completer> scriptCompleters()
Description copied from interface:ConsoleEngineReturns script and variable completers- Specified by:
scriptCompletersin interfaceConsoleEngine- Returns:
- script and variable completers
-
scripts
public Map<String,Boolean> scripts()
Description copied from interface:ConsoleEngineReturns all scripts found from PATH- Specified by:
scriptsin interfaceConsoleEngine- Returns:
- map keys have script file names and value is true if it is console script
-
expandParameters
public Object[] expandParameters(String[] args) throws Exception
Description copied from interface:ConsoleEngineSubstituting args references with their values.- Specified by:
expandParametersin interfaceConsoleEngine- Parameters:
args- the arguments to be expanded- Returns:
- expanded arguments
- Throws:
Exception- in case of error
-
expandToList
public String expandToList(List<String> params)
Description copied from interface:ConsoleEngineExpands parameter list to string- Specified by:
expandToListin interfaceConsoleEngine- Parameters:
params- list of script parameters- Returns:
- expanded parameters list
-
execute
public Object execute(File script, String cmdLine, String[] args) throws Exception
Description copied from interface:ConsoleEngineExecutes either JLine or ScriptEngine script.- Specified by:
executein interfaceConsoleEngine- Parameters:
script- script filecmdLine- raw command lineargs- script arguments- Returns:
- script execution result
- Throws:
Exception- in case of error
-
expandCommandLine
public String expandCommandLine(String line)
Description copied from interface:ConsoleEngineSubstitutes command line with system registry invoke method call.- Specified by:
expandCommandLinein interfaceConsoleEngine- Parameters:
line- command line to be expanded- Returns:
- expanded command line
-
execute
public Object execute(String cmd, String line, String[] args) throws Exception
Description copied from interface:ConsoleEngineExecutes command line that does not contain known command by the system registry. If the line is neither JLine or ScriptEngine script it will be evaluated as ScriptEngine statement.- Specified by:
executein interfaceConsoleEngine- Parameters:
cmd- parsed command/script nameline- raw command lineargs- parsed arguments of the command- Returns:
- command line execution result
- Throws:
Exception- in case of error
-
purge
public void purge()
Description copied from interface:ConsoleEngineDelete temporary console variables- Specified by:
purgein interfaceConsoleEngine
-
putVariable
public void putVariable(String name, Object value)
Description copied from interface:ConsoleEngineCreate console variable- Specified by:
putVariablein interfaceConsoleEngine- Parameters:
name- name of the variablevalue- value of the variable
-
getVariable
public Object getVariable(String name)
Description copied from interface:ConsoleEngineGet variable value- Specified by:
getVariablein interfaceConsoleEngine- Parameters:
name- name of the variable- Returns:
- variable value
-
hasVariable
public boolean hasVariable(String name)
Description copied from interface:ConsoleEngineTest if variable with name exists- Specified by:
hasVariablein interfaceConsoleEngine- Parameters:
name- name of the variable- Returns:
- true if variable with name exists
-
executeWidget
public boolean executeWidget(Object function)
Description copied from interface:ConsoleEngineExecute widget function- Specified by:
executeWidgetin interfaceConsoleEngine- Parameters:
function- to execute- Returns:
- true on success
-
consoleOption
public <T> T consoleOption(String option, T defval)
Description copied from interface:ConsoleEngineRead console option value- Specified by:
consoleOptionin interfaceConsoleEngine- Type Parameters:
T- option type- Parameters:
option- option namedefval- default value- Returns:
- option value
-
postProcess
public ConsoleEngine.ExecutionResult postProcess(String line, Object result, String output)
Description copied from interface:ConsoleEnginePost processes execution result. If result is to be assigned to the console variable then method will return null.- Specified by:
postProcessin interfaceConsoleEngine- Parameters:
line- command lineresult- command result to processoutput- command redirected output- Returns:
- processed result
-
postProcess
public ConsoleEngine.ExecutionResult postProcess(Object result)
Description copied from interface:ConsoleEnginePost processes execution result.- Specified by:
postProcessin interfaceConsoleEngine- Parameters:
result- command result to process- Returns:
- processed result
-
invoke
public Object invoke(CommandRegistry.CommandSession session, String command, Object... args) throws Exception
Description copied from interface:CommandRegistryExecute a command.- Specified by:
invokein interfaceCommandRegistry- Overrides:
invokein classAbstractCommandRegistry- Parameters:
session- the data of the current command sessioncommand- the name of the commandargs- arguments of the command- Returns:
- result of the command execution
- Throws:
Exception- in case of error
-
trace
public void trace(Object object)
- Specified by:
tracein interfaceConsoleEngine- Parameters:
object- object to print
-
println
public void println(Object object)
Description copied from interface:ConsoleEnginePrint object.- Specified by:
printlnin interfaceConsoleEngine- Parameters:
object- object to print
-
persist
public void persist(Path file, Object object)
Description copied from interface:ConsoleEnginePersist object to file- Specified by:
persistin interfaceConsoleEngine- Parameters:
file- file where object should be writtenobject- object to persist
-
slurp
public Object slurp(Path file) throws IOException
Description copied from interface:ConsoleEngineRead object from file- Specified by:
slurpin interfaceConsoleEngine- Parameters:
file- file from where object should be read- Returns:
- object
- Throws:
IOException- in case of error
-
-