From f4bcc526fd335c699231513748d01277b4542fd2 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Sun, 7 Feb 2010 14:14:53 -0500 Subject: Adding usage and start of controllers. --- kronos/cli.py | 31 ++++++++++++++++++++++++++++--- kronos/controllers.py | 20 ++++++++++++++++++++ kronos/tests/test_cli.py | 9 ++++++++- 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 kronos/controllers.py diff --git a/kronos/cli.py b/kronos/cli.py index bdb5274..72f0676 100644 --- a/kronos/cli.py +++ b/kronos/cli.py @@ -11,19 +11,44 @@ Kronos Command Line UI 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.parse_args() + self.controllers = { + 'start': StartController(), + 'stop': StopController(), + } - def parse_args(self): + 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): - pass + 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() diff --git a/kronos/controllers.py b/kronos/controllers.py new file mode 100644 index 0000000..781a349 --- /dev/null +++ b/kronos/controllers.py @@ -0,0 +1,20 @@ +# vim: set filencoding=utf8 +""" +Controllers for Kronos + +@author: Mike Crute (mcrute@ag.com) +@organization: American Greetings Interactive +@date: February 07, 2010 +""" + + +class StartController(object): + + def __call__(self, action): + pass + + +class StopController(object): + + def __call__(self, action): + pass diff --git a/kronos/tests/test_cli.py b/kronos/tests/test_cli.py index c3b8e4d..54aef81 100644 --- a/kronos/tests/test_cli.py +++ b/kronos/tests/test_cli.py @@ -8,7 +8,7 @@ Test Suite for Command Line UI """ -from nose.tools import assert_equals +from nose.tools import assert_equals, assert_raises from kronos.cli import CommandLineUI from kronos.model import Activity @@ -27,3 +27,10 @@ class TestWhenParsingArgs(object): assert isinstance(self.ui.activity, Activity) assert_equals(self.ui.activity.activity, 'my action') assert_equals(self.ui.activity.category, 'home') + + +class TestParsingErrors(object): + + def test_should_exit_if_not_enough_args(self): + ui = CommandLineUI([]) + assert_raises(SystemExit, ui.run) -- cgit v1.2.3