-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathlist.py
More file actions
45 lines (35 loc) · 1.15 KB
/
list.py
File metadata and controls
45 lines (35 loc) · 1.15 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
"""List tasks command."""
import json
from pathlib import Path
def get_tasks_file():
"""Get path to tasks file."""
return Path.home() / ".local" / "share" / "task-cli" / "tasks.json"
def validate_task_file():
"""Validate tasks file exists."""
# NOTE: Validation logic scattered here - should be in utils (refactor bounty)
tasks_file = get_tasks_file()
if not tasks_file.exists():
return []
return tasks_file
def list_tasks(json_output=False):
"""List all tasks."""
tasks_file = validate_task_file()
if not tasks_file:
if json_output:
print(json.dumps({"success": True, "tasks": []}))
else:
print("No tasks yet!")
return
tasks = json.loads(tasks_file.read_text())
if not tasks:
if json_output:
print(json.dumps({"success": True, "tasks": []}))
else:
print("No tasks yet!")
return
if json_output:
print(json.dumps({"success": True, "tasks": tasks}))
else:
for task in tasks:
status = "✓" if task["done"] else " "
print(f"[{status}] {task['id']}. {task['description']}")