commandbox.system

Class Shell

lucee.Component
    extended by commandbox.system.Shell

Copyright Since 2005 ColdBox Platform by Ortus Solutions, Corp www.coldbox.org | www.ortussolutions.com The CommandBox Shell Object that controls the shell

Class Attributes:
  • singleton
  •  
  • synchronized : false
  •  
  • accessors : true
  •  
  • persistent : false
  •  
  • author : Brad Wood, Luis Majano, Denny Valliant
  •  
    Property Summary
    type property default serializable required
    any CommandCompletor


    • access = public
    • returntype = any
    • inject = CommandCompletor
    true false
    any CommandHighlighter


    • access = public
    • returntype = any
    • inject = CommandHighlighter
    true false
    any InterceptorService


    • access = public
    • returntype = any
    • inject = InterceptorService
    true false
    any LogBox


    • access = public
    • returntype = any
    • inject = logbox
    true false
    any ModuleService


    • access = public
    • returntype = any
    • inject = ModuleService
    true false
    any REPLCompletor


    • access = public
    • returntype = any
    • inject = REPLCompletor
    true false
    any REPLHighlighter


    • access = public
    • returntype = any
    • inject = REPLHighlighter
    true false
    any Util


    • access = public
    • returntype = any
    • inject = wirebox.system.core.util.Util
    true false
    any WireBox


    • access = public
    • returntype = any
    • inject = wirebox
    true false
    any commandService


    • access = public
    • returntype = any
    • inject = CommandService
    true false
    any configService


    • access = public
    • returntype = any
    • inject = configService
    true false
    any cr


    • access = public
    • returntype = any
    • inject = cr@constants
    true false
    Boolean doClearScreen
          Clear screen after reload.

    • access = public
    • returntype = any
    false true false
    any fileSystem


    • access = public
    • returntype = any
    • inject = FileSystem
    true false
    any formatterUtil


    • access = public
    • returntype = any
    • inject = Formatter
    true false
    Boolean keepRunning
          Bit that tells the shell to keep running.

    • access = public
    • returntype = any
    true true false
    any loaderVersion
          The loader version number.

    • access = public
    • returntype = any
    true false
    any logger


    • access = public
    • returntype = any
    • inject = logbox:logger:{this}
    true false
    any print


    • access = public
    • returntype = any
    • inject = print
    true false
    any pwd
          The Current Working Directory.

    • access = public
    • returntype = any
    true false
    any reader
          The java jline reader class.

    • access = public
    • returntype = any
    true false
    any readerFactory


    • access = public
    • returntype = any
    • inject = ReaderFactory
    true false
    Boolean reloadShell
          Bit that is used to reload the shell.

    • access = public
    • returntype = any
    false true false
    any shellPrompt
          The default shell prompt.

    • access = public
    • returntype = any
    true false
    any shellType
          This value is either "interactive" meaning the shell stays open waiting for user input.

    • access = public
    • returntype = any
    interactive true false
    any systemSettings


    • access = public
    • returntype = any
    • inject = SystemSettings
    true false
    any version
          The shell version number.

    • access = public
    • returntype = any
    true false
    Constructor Summary
    init([any inStream], [any outputStream], string userDir, string tempDir, [boolean asyncLoad='true'])
          constructor.
    Method Summary
    string ask([any message], [string mask=''], [string defaultResponse=''], [any keepHistory='false'], [any highlight='false'], [any complete='false'])
         ask the user a question and wait for response.
    any callCommand(any command, [any returnOutput='false'], [string piped], [boolean initialCommand='false'])
         Call a command.
    string cd([any directory=''])
         Changes the current directory of the shell and returns the directory set.
    any checkInterrupted([any thisThread])
         Call this method periodically in a long-running task to check and see.
    Shell clearScreen()
         clears the console.
    boolean confirm(any message)
         Ask the user a question looking for a yes/no response.
    any enableCompletion([boolean enable='true'])
         Enable or disables tab completion in the shell.
    any enableHighlighter([boolean enable='true'])
         Enable or disables highlighting in the shell.
    any enableHistory([boolean enable='true'])
         Enable or disables history in the shell.
    Shell exit()
         Exists the shell.
    string getCommandCompletor()
    string getCommandHighlighter()
    string getCommandService()
    string getConfigService()
    string getCr()
    string getDoClearScreen()
    any getExitCode()
         Gets the last Exit code to be used.
    string getFileSystem()
    string getFormatterUtil()
    string getInterceptorService()
    string getKeepRunning()
    string getLoaderVersion()
    string getLogBox()
    string getLogger()
    any getMainThread()
    string getModuleService()
    string getPrint()
    string getPwd()
    string getREPLCompletor()
    string getREPLHighlighter()
    string getReader()
    string getReaderFactory()
    string getReloadShell()
    string getShellPrompt()
    string getShellType()
    string getSystemSettings()
    string getTempDir()
         Get the temp dir in a safe manner.
    any getTermHeight()
         Get's terminal height.
    any getTermWidth()
         Get's terminal width.
    string getText()
         Returns the current console text.
    string getUtil()
    string getVersion()
    string getWireBox()
    any isTerminalInteractive()
         Is the current terminal interactive?.
    any onDIComplete()
         Finish configuring the shell.
    Shell printError(any err)
         print an error to the console.
    Shell printString(any string)
         Prints a string to the reader console with auto flush.
    any pwd()
         Alias to get's current directory or use getPWD().
    Shell reload([Boolean clear='true'])
         Sets reload flag, relaoded from shell.
    boolean run([any silent='false'])
         Runs the shell thread until exit flag is set.
    any setCommandCompletor(any CommandCompletor)
    any setCommandHighlighter(any CommandHighlighter)
    any setCommandService(any commandService)
    any setCompletor([string completorName], [any executor])
         Set the shell's completor.
    any setConfigService(any configService)
    any setCr(any cr)
    any setDoClearScreen(Boolean doClearScreen)
    Shell setExitCode(string exitCode)
         Sets the OS Exit code to be used.
    any setFileSystem(any fileSystem)
    any setFormatterUtil(any formatterUtil)
    any setHighlighter([string highlighterName])
         Set the shell's highlighter.
    any setHistory([any filePath])
         Use this wrapper method to change the history file in use by the shell.
    any setInterceptorService(any InterceptorService)
    any setKeepRunning(Boolean keepRunning)
    any setLoaderVersion(any loaderVersion)
    any setLogBox(any LogBox)
    any setLogger(any logger)
    any setModuleService(any ModuleService)
    any setPrint(any print)
    Shell setPrompt([any text=''])
         Sets the shell prompt.
    any setPwd(any pwd)
    any setREPLCompletor(any REPLCompletor)
    any setREPLHighlighter(any REPLHighlighter)
    any setReader(any reader)
    any setReaderFactory(any readerFactory)
    any setReloadShell(Boolean reloadShell)
    any setShellPrompt(any shellPrompt)
    any setShellType(any shellType)
    any setSystemSettings(any systemSettings)
    Shell setTempDir(any directory)
         sets and renews temp directory.
    any setUtil(any Util)
    any setVersion(any version)
    any setWireBox(any WireBox)
    any shutdown()
         Shutdown the shell and close/release any resources associated.
    string waitForKey([any message=''])
         Wait until the user's next keystroke, returns the key pressed.
     
    Methods inherited from class lucee.Component
    None

    Constructor Detail

    init

    public init([any inStream], [any outputStream], string userDir, string tempDir, [boolean asyncLoad='true'])

    constructor

    Parameters:
    inStream - input stream if running externally
    outputStream - output stream if running externally
    userDir - The user directory
    tempDir - The temp directory
    asyncLoad

    Property Detail

    CommandCompletor

    property any CommandCompletor

    Attributes:
    access - public
    required - false
    returntype - any
    inject - CommandCompletor
    serializable - true

    CommandHighlighter

    property any CommandHighlighter

    Attributes:
    access - public
    required - false
    returntype - any
    inject - CommandHighlighter
    serializable - true

    InterceptorService

    property any InterceptorService

    Attributes:
    access - public
    required - false
    returntype - any
    inject - InterceptorService
    serializable - true

    LogBox

    property any LogBox

    Attributes:
    access - public
    required - false
    returntype - any
    inject - logbox
    serializable - true

    ModuleService

    property any ModuleService

    Attributes:
    access - public
    required - false
    returntype - any
    inject - ModuleService
    serializable - true

    REPLCompletor

    property any REPLCompletor

    Attributes:
    access - public
    required - false
    returntype - any
    inject - REPLCompletor
    serializable - true

    REPLHighlighter

    property any REPLHighlighter

    Attributes:
    access - public
    required - false
    returntype - any
    inject - REPLHighlighter
    serializable - true

    Util

    property any Util

    Attributes:
    access - public
    required - false
    returntype - any
    inject - wirebox.system.core.util.Util
    serializable - true

    WireBox

    property any WireBox

    Attributes:
    access - public
    required - false
    returntype - any
    inject - wirebox
    serializable - true

    commandService

    property any commandService

    Attributes:
    access - public
    required - false
    returntype - any
    inject - CommandService
    serializable - true

    configService

    property any configService

    Attributes:
    access - public
    required - false
    returntype - any
    inject - configService
    serializable - true

    cr

    property any cr

    Attributes:
    access - public
    required - false
    returntype - any
    inject - cr@constants
    serializable - true

    doClearScreen

    property Boolean doClearScreen = [false]

    Clear screen after reload

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    fileSystem

    property any fileSystem

    Attributes:
    access - public
    required - false
    returntype - any
    inject - FileSystem
    serializable - true

    formatterUtil

    property any formatterUtil

    Attributes:
    access - public
    required - false
    returntype - any
    inject - Formatter
    serializable - true

    keepRunning

    property Boolean keepRunning = [true]

    Bit that tells the shell to keep running

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    loaderVersion

    property any loaderVersion

    The loader version number

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    logger

    property any logger

    Attributes:
    access - public
    required - false
    returntype - any
    inject - logbox:logger:{this}
    serializable - true

    print

    property any print

    Attributes:
    access - public
    required - false
    returntype - any
    inject - print
    serializable - true

    pwd

    property any pwd

    The Current Working Directory

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    reader

    property any reader

    The java jline reader class.

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    readerFactory

    property any readerFactory

    Attributes:
    access - public
    required - false
    returntype - any
    inject - ReaderFactory
    serializable - true

    reloadShell

    property Boolean reloadShell = [false]

    Bit that is used to reload the shell

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    shellPrompt

    property any shellPrompt

    The default shell prompt

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    shellType

    property any shellType = [interactive]

    This value is either "interactive" meaning the shell stays open waiting for user input or "command" which means a single command will be run and then the shell will be exiting. This differentiation may be useful for commands who want to be careful not to leave threads running that they expect to finish since the JVM will terminiate immedatley after the command finishes. This could also be useful to reduce the amount of extra text that's output such as the CommandBox banner which isn't really needed for a one-off command, especially if the output of that command needs to be fed into another OS command.

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    systemSettings

    property any systemSettings

    Attributes:
    access - public
    required - false
    returntype - any
    inject - SystemSettings
    serializable - true

    version

    property any version

    The shell version number

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    Method Detail

    ask

    public string ask([any message], [string mask=''], [string defaultResponse=''], [any keepHistory='false'], [any highlight='false'], [any complete='false'])

    ask the user a question and wait for response

    Parameters:
    message - message to prompt the user with
    mask - When not empty, keyboard input is masked as that character
    defaultResponse - Text to populate the buffer with by default that will be submitted if the user presses enter without typing anything
    keepHistory - True to remeber the text typed in the shell history
    highlight
    complete
    Returns:
    the response from the user

    callCommand

    public any callCommand(any command, [any returnOutput='false'], [string piped], [boolean initialCommand='false'])

    Call a command In other words, if "foo" calls "bar", which calls "baz" and baz errors, all three commands are scrapped and do not finish execution.

    Parameters:
    command - Either a string containing a text command, or an array of tokens representing the command and parameters.
    returnOutput - True will return the output of the command as a string, false will send the output to the console. If command outputs nothing, an empty string will come back.
    piped - Any text being piped into the command. This will overwrite the first parameter (pushing any positional params back)
    initialCommand - Since commands can recursivley call new commands via this method, this flags the first in the chain so exceptions can bubble all the way back to the beginning.

    cd

    public string cd([any directory=''])

    Changes the current directory of the shell and returns the directory set.

    Parameters:
    directory - directory to CD to. Please verify it exists before calling.

    checkInterrupted

    public any checkInterrupted([any thisThread])

    Call this method periodically in a long-running task to check and see if the user has hit Ctrl-C. This method will throw an UserInterruptException which you should not catch. It will unroll the stack all the way back to the shell

    Parameters:
    thisThread

    clearScreen

    public Shell clearScreen()

    clears the console


    confirm

    public boolean confirm(any message)

    Ask the user a question looking for a yes/no response

    Parameters:
    message - message to prompt the user with
    Returns:
    the response from the user as a boolean value

    enableCompletion

    public any enableCompletion([boolean enable='true'])

    Enable or disables tab completion in the shell

    Parameters:
    enable - Pass true to enable, false to disable

    enableHighlighter

    public any enableHighlighter([boolean enable='true'])

    Enable or disables highlighting in the shell

    Parameters:
    enable - Pass true to enable, false to disable

    enableHistory

    public any enableHistory([boolean enable='true'])

    Enable or disables history in the shell

    Parameters:
    enable - Pass true to enable, false to disable

    exit

    public Shell exit()

    Exists the shell


    getCommandCompletor

    public string getCommandCompletor()


    getCommandHighlighter

    public string getCommandHighlighter()


    getCommandService

    public string getCommandService()


    getConfigService

    public string getConfigService()


    getCr

    public string getCr()


    getDoClearScreen

    public string getDoClearScreen()


    getExitCode

    public any getExitCode()

    Gets the last Exit code to be used


    getFileSystem

    public string getFileSystem()


    getFormatterUtil

    public string getFormatterUtil()


    getInterceptorService

    public string getInterceptorService()


    getKeepRunning

    public string getKeepRunning()


    getLoaderVersion

    public string getLoaderVersion()


    getLogBox

    public string getLogBox()


    getLogger

    public string getLogger()


    getMainThread

    public any getMainThread()


    getModuleService

    public string getModuleService()


    getPrint

    public string getPrint()


    getPwd

    public string getPwd()


    getREPLCompletor

    public string getREPLCompletor()


    getREPLHighlighter

    public string getREPLHighlighter()


    getReader

    public string getReader()


    getReaderFactory

    public string getReaderFactory()


    getReloadShell

    public string getReloadShell()


    getShellPrompt

    public string getShellPrompt()


    getShellType

    public string getShellType()


    getSystemSettings

    public string getSystemSettings()


    getTempDir

    public string getTempDir()

    Get the temp dir in a safe manner


    getTermHeight

    public any getTermHeight()

    Get's terminal height


    getTermWidth

    public any getTermWidth()

    Get's terminal width


    getText

    public string getText()

    Returns the current console text


    getUtil

    public string getUtil()


    getVersion

    public string getVersion()


    getWireBox

    public string getWireBox()


    isTerminalInteractive

    public any isTerminalInteractive()

    Is the current terminal interactive?


    onDIComplete

    public any onDIComplete()

    Finish configuring the shell


    printError

    public Shell printError(any err)

    print an error to the console

    Parameters:
    err - Error object to print (only message is required)

    printString

    public Shell printString(any string)

    Prints a string to the reader console with auto flush

    Parameters:
    string - string to print (handles complex objects)

    pwd

    public any pwd()

    Alias to get's current directory or use getPWD()


    reload

    public Shell reload([Boolean clear='true'])

    Sets reload flag, relaoded from shell.cfm

    Parameters:
    clear - clears the screen after reload

    run

    public boolean run([any silent='false'])

    Runs the shell thread until exit flag is set

    Parameters:
    silent - Supress prompt

    setCommandCompletor

    public any setCommandCompletor(any CommandCompletor)

    Parameters:
    CommandCompletor

    setCommandHighlighter

    public any setCommandHighlighter(any CommandHighlighter)

    Parameters:
    CommandHighlighter

    setCommandService

    public any setCommandService(any commandService)

    Parameters:
    commandService

    setCompletor

    public any setCompletor([string completorName], [any executor])

    Set the shell's completor

    Parameters:
    completorName - Pass "command", "repl", or "dummy"
    executor - If using REPL completor, pass an optional executor for better completion results

    setConfigService

    public any setConfigService(any configService)

    Parameters:
    configService

    setCr

    public any setCr(any cr)

    Parameters:
    cr

    setDoClearScreen

    public any setDoClearScreen(Boolean doClearScreen)

    Parameters:
    doClearScreen

    setExitCode

    public Shell setExitCode(string exitCode)

    Sets the OS Exit code to be used

    Parameters:
    exitCode

    setFileSystem

    public any setFileSystem(any fileSystem)

    Parameters:
    fileSystem

    setFormatterUtil

    public any setFormatterUtil(any formatterUtil)

    Parameters:
    formatterUtil

    setHighlighter

    public any setHighlighter([string highlighterName])

    Set the shell's highlighter

    Parameters:
    highlighterName - Pass "command", "repl", or "dummy"

    setHistory

    public any setHistory([any filePath])

    Use this wrapper method to change the history file in use by the shell.

    Parameters:
    filePath - The path to the history file to set

    setInterceptorService

    public any setInterceptorService(any InterceptorService)

    Parameters:
    InterceptorService

    setKeepRunning

    public any setKeepRunning(Boolean keepRunning)

    Parameters:
    keepRunning

    setLoaderVersion

    public any setLoaderVersion(any loaderVersion)

    Parameters:
    loaderVersion

    setLogBox

    public any setLogBox(any LogBox)

    Parameters:
    LogBox

    setLogger

    public any setLogger(any logger)

    Parameters:
    logger

    setModuleService

    public any setModuleService(any ModuleService)

    Parameters:
    ModuleService

    setPrint

    public any setPrint(any print)

    Parameters:
    print

    setPrompt

    public Shell setPrompt([any text=''])

    Sets the shell prompt

    Parameters:
    text - prompt text to set, if empty we use the default prompt

    setPwd

    public any setPwd(any pwd)

    Parameters:
    pwd

    setREPLCompletor

    public any setREPLCompletor(any REPLCompletor)

    Parameters:
    REPLCompletor

    setREPLHighlighter

    public any setREPLHighlighter(any REPLHighlighter)

    Parameters:
    REPLHighlighter

    setReader

    public any setReader(any reader)

    Parameters:
    reader

    setReaderFactory

    public any setReaderFactory(any readerFactory)

    Parameters:
    readerFactory

    setReloadShell

    public any setReloadShell(Boolean reloadShell)

    Parameters:
    reloadShell

    setShellPrompt

    public any setShellPrompt(any shellPrompt)

    Parameters:
    shellPrompt

    setShellType

    public any setShellType(any shellType)

    Parameters:
    shellType

    setSystemSettings

    public any setSystemSettings(any systemSettings)

    Parameters:
    systemSettings

    setTempDir

    public Shell setTempDir(any directory)

    sets and renews temp directory

    Parameters:
    directory - directory to use

    setUtil

    public any setUtil(any Util)

    Parameters:
    Util

    setVersion

    public any setVersion(any version)

    Parameters:
    version

    setWireBox

    public any setWireBox(any WireBox)

    Parameters:
    WireBox

    shutdown

    public any shutdown()

    Shutdown the shell and close/release any resources associated. This isn't guaranteed to run if the shell is closed, but it will run for a reload command


    waitForKey

    public string waitForKey([any message=''])

    Wait until the user's next keystroke, returns the key pressed

    Parameters:
    message
    Returns:
    character of key pressed or key binding name.