old_contents: import logging
  import os
  
  from brain import Brain
  
  from cmdparse import Command
  
  log = logging.getLogger("hal")
  
  class InitCommand(Command):
      def __init__(self):
          Command.__init__(self, "init", summary="Initialize a new brain")
  
          self.add_option("", "--force", action="store_true") 
          self.add_option("", "--order", type="int", default=5)
  
      def run(self, options, args):
          filename = "hal.brain"
  
          if os.path.exists(filename):
              if options.force:
                  os.remove(filename)
              else:
                  log.error("%s already exists!", filename)
                  return
  
          Brain.init(filename, options.order)
  
  class CloneCommand(Command):
      def __init__(self):
          Command.__init__(self, "clone", summary="Clone a MegaHAL brain")
  
      def run(self, options, args):
          if len(args) != 1:
              log.error("usage: clone <MegaHAL brain>")
              return
  
          if os.path.exists("hal.brain"):
              log.error("hal.brain already exists")
              return
  
          megahal_brain = args[0]
  
          Brain.init("hal.brain")
          b.clone(megahal_brain)
  
  class LearnCommand(Command):
      def __init__(self):
          Command.__init__(self, "learn", summary="Learn a file of text")
  
      def run(self, options, args):
          if len(args) != 1:
              log.error("usage: learn <text file>")
              return
  
          filename = args[0]
  
          b = Brain("hal.brain")
  
          fd = open(filename)
          for line in fd.xreadlines():
              b.learn(line.strip())
  
new_contents: import logging
  import os
  import readline
  import sys
  
  from brain import Brain
  
  from cmdparse import Command
  
  log = logging.getLogger("hal")
  
  class InitCommand(Command):
      def __init__(self):
          Command.__init__(self, "init", summary="Initialize a new brain")
  
          self.add_option("", "--force", action="store_true") 
          self.add_option("", "--order", type="int", default=5)
  
      def run(self, options, args):
          filename = "hal.brain"
  
          if os.path.exists(filename):
              if options.force:
                  os.remove(filename)
              else:
                  log.error("%s already exists!", filename)
                  return
  
          Brain.init(filename, options.order)
  
  class CloneCommand(Command):
      def __init__(self):
          Command.__init__(self, "clone", summary="Clone a MegaHAL brain")
  
      def run(self, options, args):
          if len(args) != 1:
              log.error("usage: clone <MegaHAL brain>")
              return
  
          if os.path.exists("hal.brain"):
              log.error("hal.brain already exists")
              return
  
          megahal_brain = args[0]
  
          Brain.init("hal.brain")
          b.clone(megahal_brain)
  
  class LearnCommand(Command):
      def __init__(self):
          Command.__init__(self, "learn", summary="Learn a file of text")
  
      def run(self, options, args):
          if len(args) != 1:
              log.error("usage: learn <text file>")
              return
  
          filename = args[0]
  
          b = Brain("hal.brain")
  
          fd = open(filename)
          for line in fd.xreadlines():
              b.learn(line.strip())
  
  class ConsoleCommand(Command):
      def __init__(self):
          Command.__init__(self, "console", summary="Speak with Hal.")
  
      def run(self, options, args):
          b = Brain("hal.brain")
  
          while True:
              try:
                  cmd = raw_input("> ")
              except EOFError:
                  print
                  sys.exit(0)
  
              b.learn(cmd)
              print b.reply(cmd).capitalize()
  
subject: Add ConsoleCommand