summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2010-02-07 14:14:53 -0500
committerMike Crute <mcrute@gmail.com>2010-02-07 14:14:53 -0500
commitf4bcc526fd335c699231513748d01277b4542fd2 (patch)
treec1a4b90dd317f847e9833570883bf90693cf3dcb
parent827ff3b327e4dd0c0139aa833a122a3e0b9c2873 (diff)
downloadkronos-f4bcc526fd335c699231513748d01277b4542fd2.tar.bz2
kronos-f4bcc526fd335c699231513748d01277b4542fd2.tar.xz
kronos-f4bcc526fd335c699231513748d01277b4542fd2.zip
Adding usage and start of controllers.
-rw-r--r--kronos/cli.py31
-rw-r--r--kronos/controllers.py20
-rw-r--r--kronos/tests/test_cli.py9
3 files changed, 56 insertions, 4 deletions
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
11import sys 11import sys
12from optparse import OptionParser 12from optparse import OptionParser
13from kronos.parser import parse_activity 13from kronos.parser import parse_activity
14from kronos.controllers import StartController, StopController
14 15
15 16
16class CommandLineUI(object): 17class CommandLineUI(object):
17 18
18 def __init__(self, args): 19 def __init__(self, args):
19 self.args = args 20 self.args = args
20 self.parse_args() 21 self.controllers = {
22 'start': StartController(),
23 'stop': StopController(),
24 }
21 25
22 def parse_args(self): 26 def usage(self):
27 print "You're doin' it wrong."
28 raise SystemExit
29
30 def _parse_args(self):
23 self.action = self.args[1] 31 self.action = self.args[1]
24 32
25 activity = ' '.join(self.args[2:]) 33 activity = ' '.join(self.args[2:])
26 self.activity = parse_activity(activity) 34 self.activity = parse_activity(activity)
27 35
28 def run(self): 36 def run(self):
29 pass 37 if len(self.args) < 2:
38 self.usage()
39 else:
40 self._parse_args()
41
42 controller = self.controllers.get(self.action)
43 if not controller:
44 self.usage()
45
46 controller(self.activity)
47
48
49def main():
50 CommandLineUI(sys.argv[:]).run()
51
52
53if __name__ == "__main__":
54 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 @@
1# vim: set filencoding=utf8
2"""
3Controllers for Kronos
4
5@author: Mike Crute (mcrute@ag.com)
6@organization: American Greetings Interactive
7@date: February 07, 2010
8"""
9
10
11class StartController(object):
12
13 def __call__(self, action):
14 pass
15
16
17class StopController(object):
18
19 def __call__(self, action):
20 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
8""" 8"""
9 9
10 10
11from nose.tools import assert_equals 11from nose.tools import assert_equals, assert_raises
12from kronos.cli import CommandLineUI 12from kronos.cli import CommandLineUI
13from kronos.model import Activity 13from kronos.model import Activity
14 14
@@ -27,3 +27,10 @@ class TestWhenParsingArgs(object):
27 assert isinstance(self.ui.activity, Activity) 27 assert isinstance(self.ui.activity, Activity)
28 assert_equals(self.ui.activity.activity, 'my action') 28 assert_equals(self.ui.activity.activity, 'my action')
29 assert_equals(self.ui.activity.category, 'home') 29 assert_equals(self.ui.activity.category, 'home')
30
31
32class TestParsingErrors(object):
33
34 def test_should_exit_if_not_enough_args(self):
35 ui = CommandLineUI([])
36 assert_raises(SystemExit, ui.run)