grizzled.cmd

CommandInterpreter

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.readlinepackage. 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.

attributes: abstract
go to: companion
linear super types: AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. CommandInterpreter
  2. AnyRef
  3. Any
Visibility
  1. Public
  2. All
Impl.
  1. Concrete
  2. Abstract

Instance constructors

  1. new CommandInterpreter (appName: String)

    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)

    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 =)

    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.

Value Members

  1. def != (arg0: AnyRef) : Boolean

    attributes: final
    definition classes: AnyRef
  2. def != (arg0: Any) : Boolean

    o != arg0 is the same as !(o == (arg0)).

    o != arg0 is the same as !(o == (arg0)).

    arg0

    the object to compare against this object for dis-equality.

    returns

    false if the receiver object is equivalent to the argument; true otherwise.

    attributes: final
    definition classes: Any
  3. def ## () : Int

    attributes: final
    definition classes: AnyRef → Any
  4. def $asInstanceOf [T0] () : T0

    attributes: final
    definition classes: AnyRef
  5. def $isInstanceOf [T0] () : Boolean

    attributes: final
    definition classes: AnyRef
  6. def == (arg0: AnyRef) : Boolean

    o == arg0 is the same as if (o eq null) arg0 eq null else o.equals(arg0).

    o == arg0 is the same as if (o eq null) arg0 eq null else o.equals(arg0).

    arg0

    the object to compare against this object for equality.

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    attributes: final
    definition classes: AnyRef
  7. def == (arg0: Any) : Boolean

    o == arg0 is the same as o.equals(arg0).

    o == arg0 is the same as o.equals(arg0).

    arg0

    the object to compare against this object for equality.

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    attributes: final
    definition classes: Any
  8. val DefaultReadlineLibraryList : List[Value]

    Default list of readline libraries to try, in order.

    Default list of readline libraries to try, in order.

  9. val OutputWidth : Int

    Assumed output width of the screen.

    Assumed output width of the screen.

  10. def StartCommandIdentifier : String

    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.

  11. def allHandlers : List[CommandHandler]

    Get all handlers.

    Get all handlers. By default, this property combines thehandlers 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.

    attributes: final
  12. val appName : String

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

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

  13. def asInstanceOf [T0] : T0

    This method is used to cast the receiver object to be of type T0.

    This method is used to cast the receiver object to be of type T0.

    Note that the success of a cast at runtime is modulo Scala's erasure semantics. Therefore the expression1.asInstanceOf[String] will throw a ClassCastException at runtime, while the expressionList(1).asInstanceOf[List[String]] will not. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the requested typed.

    returns

    the receiver object.

    attributes: final
    definition classes: Any
  14. def clone () : AnyRef

    This method creates and returns a copy of the receiver object.

    This method creates and returns a copy of the receiver object.

    The default implementation of the clone method is platform dependent.

    returns

    a copy of the receiver object.

    attributes: protected
    definition classes: AnyRef
  15. def eq (arg0: AnyRef) : Boolean

    This method is used to test whether the argument (arg0) is a reference to the receiver object (this).

    This method is used to test whether the argument (arg0) is a reference to the receiver object (this).

    The eq method implements an [http://en.wikipedia.org/wiki/Equivalence_relation equivalence relation] on non-null instances of AnyRef: * It is reflexive: for any non-null instance x of type AnyRef, x.eq(x) returns true. * It is symmetric: for any non-null instances x and y of type AnyRef, x.eq(y) returns true if and only if y.eq(x) returns true. * It is transitive: for any non-null instances x, y, and z of type AnyRef if x.eq(y) returns true and y.eq(z) returns true, then x.eq(z) returns true.

    Additionally, the eq method has three other properties. * It is consistent: for any non-null instances x and y of type AnyRef, multiple invocations of x.eq(y) consistently returns true or consistently returns false. * For any non-null instance x of type AnyRef, x.eq(null) and null.eq(x) returns false. * null.eq(null) returns true.

    When overriding the equals or hashCode methods, it is important to ensure that their behavior is consistent with reference equality. Therefore, if two objects are references to each other (o1 eq o2), they should be equal to each other (o1 == o2) and they should hash to the same value (o1.hashCode == o2.hashCode).

    arg0

    the object to compare against this object for reference equality.

    returns

    true if the argument is a reference to the receiver object; false otherwise.

    attributes: final
    definition classes: AnyRef
  16. def equals (arg0: Any) : Boolean

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.

    The default implementations of this method is an [http://en.wikipedia.org/wiki/Equivalence_relation equivalence relation]: * It is reflexive: for any instance x of type Any, x.equals(x) should return true. * It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true. * It is transitive: for any instances x, y, and z of type AnyRef if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

    If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is often necessary to override hashCode to ensure that objects that are "equal" (o1.equals(o2) returns true) hash to the same scala.Int (o1.hashCode.equals(o2.hashCode)).

    arg0

    the object to compare against this object for equality.

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    definition classes: AnyRef → Any
  17. def error (message: String) : Unit

    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

  18. def finalize () : Unit

    This method is called by the garbage collector on the receiver object when garbage collection determines that there are no more references to the object.

    This method is called by the garbage collector on the receiver object when garbage collection determines that there are no more references to the object.

    The details of when and if the finalize method are invoked, as well as the interaction between finalizeand non-local returns and exceptions, are all platform dependent.

    attributes: protected
    definition classes: AnyRef
  19. def getClass () : java.lang.Class[_]

    Returns a representation that corresponds to the dynamic class of the receiver object.

    Returns a representation that corresponds to the dynamic class of the receiver object.

    The nature of the representation is platform dependent.

    returns

    a representation that corresponds to the dynamic class of the receiver object.

    attributes: final
    definition classes: AnyRef
  20. def handleCommand (commandLine: Option[String]) : CommandAction

    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.

    attributes: final
  21. def handleEOF : CommandAction

    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.

  22. def handleEmptyCommand : CommandAction

    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 returnsKeepGoing.

    returns

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

  23. def handleException (e: Exception) : CommandAction

    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 eitherKeepGoing or Stop. The default version of this method dumps the exception stack trace and returnsStop.

    e

    the exception

    returns

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

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

    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 returnsKeepGoing.

    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.

  25. val handlers : List[CommandHandler]

    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 thehelpHandler property to return your help handler, instead of the default one.

    attributes: abstract
  26. def hashCode () : Int

    Returns a hash code value for the object.

    Returns a hash code value for the object.

    The default hashing algorithm is platform dependent.

    Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

    returns

    the hash code value for the object.

    definition classes: AnyRef → Any
  27. def helpHandler : HelpHandler

    Get the help handler.

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

  28. val history : History

    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

  29. def isInstanceOf [T0] : Boolean

    This method is used to test whether the dynamic type of the receiver object is T0.

    This method is used to test whether the dynamic type of the receiver object is T0.

    Note that the test result of the test is modulo Scala's erasure semantics. Therefore the expression1.isInstanceOf[String] will return false, while the expression List(1).isInstanceOf[List[String]] will return true. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the requested typed.

    returns

    true if the receiver object is an instance of erasure of type T0; false otherwise.

    attributes: final
    definition classes: Any
  30. def mainLoop : Unit

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

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

    attributes: final
  31. def ne (arg0: AnyRef) : Boolean

    o.ne(arg0) is the same as !(o.eq(arg0)).

    o.ne(arg0) is the same as !(o.eq(arg0)).

    arg0

    the object to compare against this object for reference dis-equality.

    returns

    false if the argument is not a reference to the receiver object; true otherwise.

    attributes: final
    definition classes: AnyRef
  32. def notify () : Unit

    Wakes up a single thread that is waiting on the receiver object's monitor.

    Wakes up a single thread that is waiting on the receiver object's monitor.

    attributes: final
    definition classes: AnyRef
  33. def notifyAll () : Unit

    Wakes up all threads that are waiting on the receiver object's monitor.

    Wakes up all threads that are waiting on the receiver object's monitor.

    attributes: final
    definition classes: AnyRef
  34. def postCommand (command: String, unparsedArgs: String) : CommandAction

    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.

  35. def postLoop : Unit

    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.

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

    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.

  37. def preLoop : Unit

    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.

  38. def primaryPrompt : String

    The primary prompt string.

    The primary prompt string.

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

    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 callinghandleEOF()).

    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

  40. val readline : Readline

  41. def secondaryPrompt : String

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

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

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

    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 bazResult: Command foo, argument string "bar baz"

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

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

    Subclasses may override this method to parse commands differently.

    line

    the input type

    returns

    A (commandName, argumentString) 2-tuple

  43. def synchronized [T0] (arg0: T0) : T0

    attributes: final
    definition classes: AnyRef
  44. def toString () : String

    Returns a string representation of the object.

    Returns a string representation of the object.

    The default representation is platform dependent.

    returns

    a string representation of the object.

    definition classes: AnyRef → Any
  45. val tokenDelimiters : String

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

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

  46. def wait () : Unit

    attributes: final
    definition classes: AnyRef
  47. def wait (arg0: Long, arg1: Int) : Unit

    attributes: final
    definition classes: AnyRef
  48. def wait (arg0: Long) : Unit

    attributes: final
    definition classes: AnyRef
  49. def warning (message: String) : Unit

    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