-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
125 lines (100 loc) · 3.07 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""
Usage:
kanban todo <task_name>
kanban doing <task_id>
kanban done <task_id>
kanban edit_task <task_id>
kanban delete_task <task_id>
kanban list_todo
kanban list_doing
kanban list_done
kanban list_all
kanban quit
Options:
-h --help Show this screen.
"""
import cmd
import os
import platform
from docopt import DocoptExit, docopt
from app.kanban import ToDo
def docopt_cmd(func):
"""
This decorator simplifies the try/except block and returns
the result of parsing docopt using an action
credits: https://github.com/docopt/docopt/blob/master/examples/interactive_example.py
Contributors: JonLundy, TheWaWaR
"""
def fn(self, arg):
try:
opt = docopt(fn.__doc__, arg)
except DocoptExit as err:
# The DocoptExit is thrown when the args do not match
# We print a message to the user and the usage block
print('Invalid Command!')
print(err)
return
except SystemExit:
# The SystemExit exception prints the usage for --help
# We do not need to do the print here
return
return func(self, opt)
fn.__name__ = func.__name__
fn.__doc__ = func.__doc__
fn.__dict__.update(func.__dict__)
return fn
class Main(cmd.Cmd):
# this assumes a Windows systems... for *nix OS's, use os.system('clear')
os.system("cls") if platform.platform(
).title() == 'Windows' else os.system('clear')
prompt = "The Kanbanna>>>"
def __init__(self):
super().__init__()
self.kanban = ToDo()
@docopt_cmd
def do_todo(self, args):
"""usage: todo <task_name>"""
task_name = args["<task_name>"]
description = input("Enter description: ")
print(self.kanban.todo(task_name, description))
@docopt_cmd
def do_doing(self, args):
"""usage: doing <task_id> """
task_id = args["<task_id>"]
print(self.kanban.doing(task_id))
@docopt_cmd
def do_done(self, args):
"""usage: done <task_id>"""
task_id = args["<task_id>"]
print(self.kanban.done(task_id))
@docopt_cmd
def do_list_all(self, _):
"""usage: list_all"""
print(self.kanban.list_all())
@docopt_cmd
def do_list_todo(self, _):
"""usage: list_todo"""
print(self.kanban.list_todo())
@docopt_cmd
def do_list_doing(self, _):
"""usage: list_doing"""
print(self.kanban.list_doing())
@docopt_cmd
def do_list_done(self, _):
"""usage: list_done"""
print(self.kanban.list_done())
@docopt_cmd
def do_edit_task(self, args):
"""usage: edit_task <task_id>"""
task_id = args["<task_id>"]
print(self.kanban.edit_task(task_id))
@docopt_cmd
def do_delete_task(self, args):
"""usage: delete_task <task_id>"""
task_id = args["<task_id>"]
print(self.kanban.delete_task(task_id))
def do_quit(self, _):
"""usage: exits the application"""
print('See ya soon!')
exit()
Main().cmdloop()