Class ConsoleEngineImpl

    • Field Detail

      • VAR_CONSOLE_OPTIONS

        private static final java.lang.String VAR_CONSOLE_OPTIONS
        See Also:
        Constant Field Values
      • OPTION_HELP

        private static final java.lang.String[] OPTION_HELP
      • SLURP_FORMAT_TEXT

        private static final java.lang.String SLURP_FORMAT_TEXT
        See Also:
        Constant Field Values
      • exception

        private java.lang.Exception exception
      • scriptExtension

        private java.lang.String scriptExtension
      • workDir

        private final java.util.function.Supplier<java.nio.file.Path> workDir
      • aliases

        private final java.util.Map<java.lang.String,​java.lang.String> aliases
      • pipes

        private final java.util.Map<java.lang.String,​java.util.List<java.lang.String>> pipes
      • aliasFile

        private java.nio.file.Path aliasFile
      • executing

        private boolean executing
      • printer

        private final Printer printer
    • Constructor Detail

      • ConsoleEngineImpl

        public ConsoleEngineImpl​(ScriptEngine engine,
                                 Printer printer,
                                 java.util.function.Supplier<java.nio.file.Path> workDir,
                                 ConfigurationPath configPath)
                          throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • parser

        private Parser parser()
      • terminal

        private Terminal terminal()
      • isExecuting

        public boolean isExecuting()
        Specified by:
        isExecuting in interface ConsoleEngine
        Returns:
        true if consoleEngine is executing script
      • setScriptExtension

        public void setScriptExtension​(java.lang.String extension)
        Description copied from interface: ConsoleEngine
        Sets file name extension used by console scripts
        Specified by:
        setScriptExtension in interface ConsoleEngine
        Parameters:
        extension - console script file extension
      • hasAlias

        public boolean hasAlias​(java.lang.String name)
        Description copied from interface: ConsoleEngine
        Returns true if alias 'name' exists
        Specified by:
        hasAlias in interface ConsoleEngine
        Parameters:
        name - alias name
        Returns:
        true if alias exists
      • getAlias

        public java.lang.String getAlias​(java.lang.String name)
        Description copied from interface: ConsoleEngine
        Returns alias 'name' value
        Specified by:
        getAlias in interface ConsoleEngine
        Parameters:
        name - alias name
        Returns:
        value of alias
      • getPipes

        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getPipes()
        Description copied from interface: ConsoleEngine
        Returns defined pipes
        Specified by:
        getPipes in interface ConsoleEngine
        Returns:
        map of defined pipes
      • getNamedPipes

        public java.util.List<java.lang.String> getNamedPipes()
        Description copied from interface: ConsoleEngine
        Returns named pipe names
        Specified by:
        getNamedPipes in interface ConsoleEngine
        Returns:
        list of named pipe names
      • scriptCompleters

        public java.util.List<Completer> scriptCompleters()
        Description copied from interface: ConsoleEngine
        Returns script and variable completers
        Specified by:
        scriptCompleters in interface ConsoleEngine
        Returns:
        script and variable completers
      • commandAliasNames

        private java.util.Set<java.lang.String> commandAliasNames()
      • scriptNames

        private java.util.Set<java.lang.String> scriptNames()
      • scripts

        public java.util.Map<java.lang.String,​java.lang.Boolean> scripts()
        Description copied from interface: ConsoleEngine
        Returns all scripts found from PATH
        Specified by:
        scripts in interface ConsoleEngine
        Returns:
        map keys have script file names and value is true if it is console script
      • expandParameters

        public java.lang.Object[] expandParameters​(java.lang.String[] args)
                                            throws java.lang.Exception
        Description copied from interface: ConsoleEngine
        Substituting args references with their values.
        Specified by:
        expandParameters in interface ConsoleEngine
        Parameters:
        args - the arguments to be expanded
        Returns:
        expanded arguments
        Throws:
        java.lang.Exception - in case of error
      • expandToList

        private java.lang.String expandToList​(java.lang.String[] args)
      • expandToList

        public java.lang.String expandToList​(java.util.List<java.lang.String> params)
        Description copied from interface: ConsoleEngine
        Expands parameter list to string
        Specified by:
        expandToList in interface ConsoleEngine
        Parameters:
        params - list of script parameters
        Returns:
        expanded parameters list
      • expandName

        private java.lang.String expandName​(java.lang.String name)
      • isNumber

        private boolean isNumber​(java.lang.String str)
      • isCodeBlock

        private boolean isCodeBlock​(java.lang.String line)
      • isCommandLine

        private boolean isCommandLine​(java.lang.String line)
      • quote

        private java.lang.String quote​(java.lang.String var)
      • scriptExtensions

        private java.util.List<java.lang.String> scriptExtensions()
      • execute

        public java.lang.Object execute​(java.io.File script,
                                        java.lang.String cmdLine,
                                        java.lang.String[] args)
                                 throws java.lang.Exception
        Description copied from interface: ConsoleEngine
        Executes either JLine or ScriptEngine script.
        Specified by:
        execute in interface ConsoleEngine
        Parameters:
        script - script file
        cmdLine - raw command line
        args - script arguments
        Returns:
        script execution result
        Throws:
        java.lang.Exception - in case of error
      • expandCommandLine

        public java.lang.String expandCommandLine​(java.lang.String line)
        Description copied from interface: ConsoleEngine
        Substitutes command line with system registry invoke method call.
        Specified by:
        expandCommandLine in interface ConsoleEngine
        Parameters:
        line - command line to be expanded
        Returns:
        expanded command line
      • execute

        public java.lang.Object execute​(java.lang.String cmd,
                                        java.lang.String line,
                                        java.lang.String[] args)
                                 throws java.lang.Exception
        Description copied from interface: ConsoleEngine
        Executes 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:
        execute in interface ConsoleEngine
        Parameters:
        cmd - parsed command/script name
        line - raw command line
        args - parsed arguments of the command
        Returns:
        command line execution result
        Throws:
        java.lang.Exception - in case of error
      • purge

        public void purge()
        Description copied from interface: ConsoleEngine
        Delete temporary console variables
        Specified by:
        purge in interface ConsoleEngine
      • putVariable

        public void putVariable​(java.lang.String name,
                                java.lang.Object value)
        Description copied from interface: ConsoleEngine
        Create console variable
        Specified by:
        putVariable in interface ConsoleEngine
        Parameters:
        name - name of the variable
        value - value of the variable
      • getVariable

        public java.lang.Object getVariable​(java.lang.String name)
        Description copied from interface: ConsoleEngine
        Get variable value
        Specified by:
        getVariable in interface ConsoleEngine
        Parameters:
        name - name of the variable
        Returns:
        variable value
      • hasVariable

        public boolean hasVariable​(java.lang.String name)
        Description copied from interface: ConsoleEngine
        Test if variable with name exists
        Specified by:
        hasVariable in interface ConsoleEngine
        Parameters:
        name - name of the variable
        Returns:
        true if variable with name exists
      • executeWidget

        public boolean executeWidget​(java.lang.Object function)
        Description copied from interface: ConsoleEngine
        Execute widget function
        Specified by:
        executeWidget in interface ConsoleEngine
        Parameters:
        function - to execute
        Returns:
        true on success
      • consoleOptions

        private java.util.Map<java.lang.String,​java.lang.Object> consoleOptions()
      • consoleOption

        public <T> T consoleOption​(java.lang.String option,
                                   T defval)
        Description copied from interface: ConsoleEngine
        Read console option value
        Specified by:
        consoleOption in interface ConsoleEngine
        Type Parameters:
        T - option type
        Parameters:
        option - option name
        defval - default value
        Returns:
        option value
      • setConsoleOption

        public void setConsoleOption​(java.lang.String name,
                                     java.lang.Object value)
        Description copied from interface: ConsoleEngine
        Set console option value
        Specified by:
        setConsoleOption in interface ConsoleEngine
        Parameters:
        name - the option name
        value - value to assign console option
      • consoleOption

        private boolean consoleOption​(java.lang.String option)
      • postProcess

        public ConsoleEngine.ExecutionResult postProcess​(java.lang.String line,
                                                         java.lang.Object result,
                                                         java.lang.String output)
        Description copied from interface: ConsoleEngine
        Post processes execution result. If result is to be assigned to the console variable then method will return null.
        Specified by:
        postProcess in interface ConsoleEngine
        Parameters:
        line - command line
        result - command result to process
        output - command redirected output
        Returns:
        processed result
      • saveResult

        private int saveResult​(java.lang.String var,
                               java.lang.Object result)
      • invoke

        public java.lang.Object invoke​(CommandRegistry.CommandSession session,
                                       java.lang.String command,
                                       java.lang.Object... args)
                                throws java.lang.Exception
        Description copied from interface: CommandRegistry
        Execute a command.
        Specified by:
        invoke in interface CommandRegistry
        Overrides:
        invoke in class AbstractCommandRegistry
        Parameters:
        session - the data of the current command session
        command - the name of the command
        args - arguments of the command
        Returns:
        result of the command execution
        Throws:
        java.lang.Exception - in case of error
      • trace

        public void trace​(java.lang.Object object)
        Specified by:
        trace in interface ConsoleEngine
        Parameters:
        object - object to print
      • error

        private void error​(java.lang.String message)
      • println

        public void println​(java.lang.Object object)
        Description copied from interface: ConsoleEngine
        Print object.
        Specified by:
        println in interface ConsoleEngine
        Parameters:
        object - object to print
      • show

        private java.lang.Object show​(CommandInput input)
      • del

        private java.lang.Object del​(CommandInput input)
      • prnt

        private java.lang.Object prnt​(CommandInput input)
      • slurpcmd

        private java.lang.Object slurpcmd​(CommandInput input)
      • persist

        public void persist​(java.nio.file.Path file,
                            java.lang.Object object)
        Description copied from interface: ConsoleEngine
        Persist object to file
        Specified by:
        persist in interface ConsoleEngine
        Parameters:
        file - file where object should be written
        object - object to persist
      • slurp

        public java.lang.Object slurp​(java.nio.file.Path file)
                               throws java.io.IOException
        Description copied from interface: ConsoleEngine
        Read object from file
        Specified by:
        slurp in interface ConsoleEngine
        Parameters:
        file - file from where object should be read
        Returns:
        object
        Throws:
        java.io.IOException - in case of error
      • slurp

        private java.lang.Object slurp​(java.nio.file.Path file,
                                       java.nio.charset.Charset encoding,
                                       java.lang.String format)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • aliascmd

        private java.lang.Object aliascmd​(CommandInput input)
      • unalias

        private java.lang.Object unalias​(CommandInput input)
      • pipe

        private java.lang.Object pipe​(CommandInput input)
      • doc

        private java.lang.Object doc​(CommandInput input)
      • urlExists

        private boolean urlExists​(java.lang.String weburl)
      • slurpCompleter

        private java.util.List<Completer> slurpCompleter​(java.lang.String command)
      • variableCompleter

        private java.util.List<Completer> variableCompleter​(java.lang.String command)
      • prntCompleter

        private java.util.List<Completer> prntCompleter​(java.lang.String command)
      • aliasCompleter

        private java.util.List<Completer> aliasCompleter​(java.lang.String command)
      • unaliasCompleter

        private java.util.List<Completer> unaliasCompleter​(java.lang.String command)
      • docs

        private java.util.List<java.lang.String> docs()
      • docCompleter

        private java.util.List<Completer> docCompleter​(java.lang.String command)