-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtask.py
More file actions
49 lines (36 loc) · 1.34 KB
/
task.py
File metadata and controls
49 lines (36 loc) · 1.34 KB
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
#!/usr/bin/env python3
"""Simple task manager CLI."""
import argparse
import sys
from pathlib import Path
from commands.add import add_task
from commands.list import list_tasks
from commands.done import mark_done
def load_config():
"""Load configuration from file."""
config_path = Path.home() / ".config" / "task-cli" / "config.yaml"
# NOTE: This will crash if config doesn't exist - known bug for bounty testing
with open(config_path) as f:
return f.read()
def main():
parser = argparse.ArgumentParser(description="Simple task manager")
subparsers = parser.add_subparsers(dest="command", help="Command to run")
# Add command
add_parser = subparsers.add_parser("add", help="Add a new task")
add_parser.add_argument("description", help="Task description")
# List command
list_parser = subparsers.add_parser("list", help="List all tasks")
# Done command
done_parser = subparsers.add_parser("done", help="Mark task as complete")
done_parser.add_argument("task_id", type=int, help="Task ID to mark done")
args = parser.parse_args()
if args.command == "add":
add_task(args.description)
elif args.command == "list":
list_tasks()
elif args.command == "done":
mark_done(args.task_id)
else:
parser.print_help()
if __name__ == "__main__":
main()