-
Notifications
You must be signed in to change notification settings - Fork 1
/
todo.py
54 lines (40 loc) · 1.15 KB
/
todo.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
import sys
from dante import Dante
db = Dante("todo.db")
collection = db["todos"]
def help():
print("Usage: todo.py <command> [args...]")
print("Commands:")
print(" list")
print(" add <todo>")
print(" remove <todo>")
print(" done <todo>")
print(" undone <todo>")
def main():
if len(sys.argv) < 2:
help()
sys.exit(-1)
command = sys.argv[1]
if command == "list":
for i, todo in enumerate(collection):
print(f"{i+1}. {todo['text']}{' (done)' if todo['done'] else ''}")
return
elif command == "help":
help()
return
if len(sys.argv) < 3:
print("Missing argument: todo")
sys.exit(-1)
todo = sys.argv[2]
if command == "add":
collection.insert({"text": todo, "done": False})
elif command == "remove":
collection.delete(text=todo)
elif command == "done":
collection.set({"done": True}, text=todo)
elif command == "undone":
collection.set({"done": False}, text=todo)
else:
print(f"Unknown command: {command} (try 'help' to see available commands)")
sys.exit(-1)
main()