summaryrefslogtreecommitdiff
path: root/kronos/cli.py
diff options
context:
space:
mode:
Diffstat (limited to 'kronos/cli.py')
-rw-r--r--kronos/cli.py31
1 files changed, 28 insertions, 3 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()