# vim: set filencoding=utf8 """ Kronos Command Line UI @author: Mike Crute (mcrute@ag.com) @organization: American Greetings Interactive @date: February 05, 2010 """ import sys from optparse import OptionParser from kronos.parser import parse_activity from kronos.controllers import StartController, StopController class CommandLineUI(object): def __init__(self, args): self.args = args self.controllers = { 'start': StartController(), 'stop': StopController(), } def usage(self): print "You're doin' it wrong." raise SystemExit def _parse_args(self): self.action = self.args[1] activity = ' '.join(self.args[2:]) self.activity = parse_activity(activity) def run(self): if len(self.args) < 2: self.usage() else: self._parse_args() controller = self.controllers.get(self.action) if not controller: self.usage() controller(self.activity) def main(): CommandLineUI(sys.argv[:]).run() if __name__ == "__main__": main()