Class CommandParser

java.lang.Object
java.lang.Thread
edu.uky.cs.nil.tt.CommandParser
All Implemented Interfaces:
Runnable

public class CommandParser extends Thread
A command parser listens (on standard input) for and executes simple text commands, like modifying the server's database and shutting the server down.
Author:
Stephen G. Ware
  • Constructor Details

    • CommandParser

      public CommandParser(Server server)
      Constructs a new command parser for a server.
      Parameters:
      server - the server on which commands will be executed
  • Method Details

    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • getCommands

      public List<CommandParser.Command> getCommands()
      Returns a list of all of the command this parser can recognize.
      Returns:
      a list of commands this parser can recognize
    • getUsage

      public String getUsage()
      Returns a documentation string showing how to use the commands this parser can recognize.
      Returns:
      a documentation string
    • add

      public void add(CommandParser.Command command)
      Adds a new command to the list of command this parser can recognize.
      Parameters:
      command - the new command that will be recognized
    • parse

      public void parse(String command) throws Exception
      Attempts to parse and execute a command from a string, typically one typed into standard input.
      Parameters:
      command - the string to attempt to parse as a command
      Throws:
      Exception - if the command cannot be parsed or if a problem occurs when executing the command