Class

grizzled.cmd

CommandInterpreter

Related Doc: package cmd

Permalink

abstract class CommandInterpreter extends AnyRef

Base class for command interpreters.

CommandInterpreter is the base class of any command interpreter. This class and the CommandHandler trait provide a simple framework for writing line-oriented command-interpreters. This framework is conceptually similar to the Python cmd module and its Cmd class, though the implementation differs substantially in places.

For reading input from the console, CommandInterpreter will use of any of the readline libraries supported by the grizzled.readline package. All of those libraries support a persistent command history, and most support command completion and command editing.

A command line consists of an initial command name, followed by a list of arguments to that command. The CommandInterpreter class's command reader automatically separates the command and the remaining arguments, via the splitCommandAndArgs() method. Parsing the arguments is left to the actual command implementation. The rules for how the command is split from the remainder of the input line are outlined in the documentation for the splitCommandAndArgs() method.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. CommandInterpreter
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new CommandInterpreter(appName: String)

    Permalink

    Alternate constructor that tries all known readline implementations, in this order:

    Alternate constructor that tries all known readline implementations, in this order:

    - GNU Readline - Editline - Getline - JLine - Simple (pure Java)

    appName

    application name

  2. new CommandInterpreter(appName: String, readline: ReadlineType)

    Permalink

    Alternate constructor taking a single readline implementation.

    Alternate constructor taking a single readline implementation. Fails if that readline implementation cannot be found.

    appName

    application name

    readline

    readline implementation

  3. new CommandInterpreter(appName: String, readlineCandidates: List[ReadlineType], tokenDelimiters: String = """ \t""")

    Permalink

    appName

    the application name, used by some readline libraries for key-binding

    readlineCandidates

    list of readline libraries to try to load, in order. The ReadlineType values are defined by the grizzled.readline package.

    tokenDelimiters

    delimiters to use when tokenizing a line for tab-completion.

Abstract Value Members

  1. abstract val handlers: List[CommandHandler]

    Permalink

    List of handlers.

    List of handlers. The subclass must define this value to contain a list of its handlers. The allHandlers property will combine this list with the help handler to get the list of all handlers. If you define your own help handler, you'll have to override the helpHandler property to return your help handler, instead of the default one.

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. val DefaultReadlineLibraryList: List[readline.Readline.ReadlineType.Value]

    Permalink

    Default list of readline libraries to try, in order.

  5. val OutputWidth: Int

    Permalink

    Assumed output width of the screen.

  6. def StartCommandIdentifier: String

    Permalink

    StartCommandIdentifier is the list of characters that are permitted as the first character of a white space-delimited, multicharacter command name.

    StartCommandIdentifier is the list of characters that are permitted as the first character of a white space-delimited, multicharacter command name. All other characters are assumed to introduce single-character commands. Subclasses may override this value to permit additional, or different, starting characters for multicharacter command names. See the splitCommandAndArgs() method for more details.

  7. final def allHandlers: List[CommandHandler]

    Permalink

    Get all handlers.

    Get all handlers. By default, this property combines the handlers value with the default help handler, HelpHandler. If you define your own help handler, you'll have to override the helpHandler property to return your help handler, instead of the default one.

  8. val appName: String

    Permalink

    the application name, used by some readline libraries for key-binding

  9. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  10. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  11. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  12. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  13. def error(message: String): Unit

    Permalink

    Emit an error message in a consistent way.

    Emit an error message in a consistent way. May be overridden by subclasses. The default implementation prints errors in red.

    message

    the message to emit

  14. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  15. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  16. final def handleCommand(commandLine: Option[String]): CommandAction

    Permalink

    Handles a command line, just as if it had been typed directly at the prompt.

    Handles a command line, just as if it had been typed directly at the prompt.

    commandLine

    the command line

    returns

    KeepGoing to tell the main loop to continue, or Stop to tell the main loop to be done.

  17. def handleEOF: CommandAction

    Permalink

    Called when an end-of-file condition is encountered while reading a command (On Unix-like systems, with some readline libraries, this happens when the user pressed Ctrl-D).

    Called when an end-of-file condition is encountered while reading a command (On Unix-like systems, with some readline libraries, this happens when the user pressed Ctrl-D). prompt. The default version of this method simply returns Stop, causing the command loop to exit.

    returns

    KeepGoing to tell the main loop to continue, or Stop to tell the main loop to be done.

  18. def handleEmptyCommand: CommandAction

    Permalink

    Called when an empty command line is entered in response to the prompt.

    Called when an empty command line is entered in response to the prompt. The default version of this method simply returns KeepGoing.

    returns

    KeepGoing to tell the main loop to continue, or Stop to tell the main loop to be done.

  19. def handleException(e: Exception): CommandAction

    Permalink

    Called when an exception occurs during the main loop.

    Called when an exception occurs during the main loop. This method can handle the exception however it wants; it must return either KeepGoing or Stop. The default version of this method dumps the exception stack trace and returns Stop.

    e

    the exception

    returns

    KeepGoing to tell the main loop to continue, or Stop to tell the main loop to be done.

  20. def handleUnknownCommand(commandName: String, unparsedArgs: String): CommandAction

    Permalink

    Called when a command is entered that isn't recognized.

    Called when a command is entered that isn't recognized. The default version of this method prints an error message and returns KeepGoing.

    commandName

    the command name

    unparsedArgs

    the command arguments

    returns

    KeepGoing to tell the main loop to continue, or Stop to tell the main loop to be done.

  21. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  22. def helpHandler: HelpHandler.type

    Permalink

    Get the help handler.

    Get the help handler. Override this property if you want to supply your own help handler.

  23. val history: History

    Permalink

    Get the history object being used to record command history.

    Get the history object being used to record command history.

    returns

    the grizzled.readline.History object

  24. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  25. final def mainLoop: Unit

    Permalink

    Repeatedly issue a prompt, accept input, parse an initial prefix from the received input, and dispatch to execution handlers.

  26. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  27. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  28. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  29. def postCommand(command: String, unparsedArgs: String): CommandAction

    Permalink

    Called after a command line is interpreted.

    Called after a command line is interpreted. The default implementation simply returns KeepGoing.

    command

    the command that invoked this handler

    unparsedArgs

    the remainder of the unparsed command line

    returns

    KeepGoing to tell the main loop to continue, or Stop to tell the main loop to be done.

  30. def postLoop: Unit

    Permalink

    Called immediately after the main loop (mainLoop()) ends its command loop, this hook method can be used for cleanup.

    Called immediately after the main loop (mainLoop()) ends its command loop, this hook method can be used for cleanup. The default implementation does nothing.

  31. def preCommand(commandLine: String): Option[String]

    Permalink

    Called just before a command line is interpreted, this hook method can edit the command.

    Called just before a command line is interpreted, this hook method can edit the command.

    commandLine

    the command line

    returns

    The possibly edited command, Some("") to signal an empty command, or None to signal EOF.

  32. def preLoop: Unit

    Permalink

    Called just before the main loop (mainLoop()) begins its command loop, this hook method can be used for initialization.

    Called just before the main loop (mainLoop()) begins its command loop, this hook method can be used for initialization. The default implementation does nothing.

  33. def primaryPrompt: String

    Permalink

    The primary prompt string.

  34. def pushReader(reader: (String) ⇒ Option[String]): Stack[(String) ⇒ Option[String]]

    Permalink

    Push a reader on the reader stack.

    Push a reader on the reader stack. The reader on top of the stack is used until it returns None (indicating EOF). Then, it is removed from the stack, and the next reader is used. When the only reader remaining on the stack returns None, the command interpreter signals an EOF condition to the subclass (by calling handleEOF()).

    The reader is a simple function that takes a prompt string (which it can choose to ignore) and returns a line of input (Some(input)) or None for EOF. The line of input, if returned, should not have a trailing newline.

    reader

    the reader function

  35. val readline: Readline

    Permalink
  36. def secondaryPrompt: String

    Permalink

    The second prompt string, used when additional input is being retrieved.

  37. def splitCommandAndArgs(line: String): (String, String)

    Permalink

    Split a command from its argument list, returning the command as one string and the remaining unparsed argument string as the other string.

    Split a command from its argument list, returning the command as one string and the remaining unparsed argument string as the other string. The commmand name is parsed from the remaining arguments using the following rules:

    - If the first non-white character if the input line is in the StartCommandIdentifier string, then the command is assumed to be a identifier that is separated from the arguments by white space. - If the first character if the input line is not in the StartCommandIdentifier string, then the command is assumed to be a single-character command, with the arguments immediately following the single character.

    The StartCommandIdentifier string is an overridable field defined by this class, consisting of the characters permitted to start a multicharacter command. By default, it consists of alphanumerics. Subclasses may override it to permit additional, or different, starting characters for multicharacter commands.

    For example, using the default identifier characters, this function will break the following commands into command + arguments as shown:

    Input: foo bar baz Result: Command foo, argument string "bar baz"

    Input: !bar Result: Command ! argument string "bar"

    Input: ? one two Result: Command ? argument string "one two"

    Subclasses may override this method to parse commands differently.

    line

    the input type

    returns

    A (commandName, argumentString) 2-tuple

  38. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  39. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  40. val tokenDelimiters: String

    Permalink

    delimiters to use when tokenizing a line for tab-completion.

  41. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  42. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  43. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  44. def warning(message: String): Unit

    Permalink

    Emit a warning message in a consistent way.

    Emit a warning message in a consistent way. May be overridden by subclasses. The default implementation prints the message with the prefix "Warning: ".

    message

    the message to emit

Inherited from AnyRef

Inherited from Any

Ungrouped