-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtaskmaster.yaml
More file actions
156 lines (137 loc) · 4.78 KB
/
Copy pathtaskmaster.yaml
File metadata and controls
156 lines (137 loc) · 4.78 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# yaml-language-server: $schema=cliffy_schema.json
name: taskmaster
version: 0.1.0
help: A task management CLI
requires:
- tabulate>=0.9.0
imports: |
import json
from datetime import datetime
from tabulate import tabulate
vars:
data_file: "tasks.json"
functions:
- |
def load_data():
try:
with open("{{data_file}}", "r") as f:
return json.load(f)
except FileNotFoundError:
return {"projects": [], "tasks": []}
- |
def save_data(data):
with open("{{data_file}}", "w") as f:
json.dump(data, f, indent=2)
- |
def format_date(date_str):
return datetime.strptime(date_str, "%Y-%m-%d").strftime("%b %d, %Y")
types:
ProjectName: str = typer.Argument(..., help="Name of the project")
TaskName: str = typer.Argument(..., help="Name of the task")
DueDate: str = typer.Option(None, "--due", "-d", help="Due date (YYYY-MM-DD)")
Priority: int = typer.Option(1, "--priority", "-p", help="Priority (1-5)", min=1, max=5)
commands:
project.add:
params: [name: ProjectName]
run: |
data = load_data()
if name not in data["projects"]:
data["projects"].append(name)
save_data(data)
print(f"Project '{name}' added successfully.")
else:
print(f"Project '{name}' already exists.")
project.list:
run: |
data = load_data()
if data["projects"]:
print("Projects:")
for project in data["projects"]:
print(f"- {project}")
else:
print("No projects found.")
project.remove:
params: [name: ProjectName]
run: |
data = load_data()
if name in data["projects"]:
data["projects"].remove(name)
data["tasks"] = [task for task in data["tasks"] if task["project"] != name]
save_data(data)
print(f"Project '{name}' and its tasks removed successfully.")
else:
print(f"Project '{name}' not found.")
task.add:
params: [project: ProjectName, name: TaskName, due_date: DueDate, priority: Priority]
run: |
data = load_data()
if project not in data["projects"]:
print(f"Project '{project}' not found. Please create the project first.")
return
task = {
"project": project,
"name": name,
"due_date": due_date,
"priority": priority,
"completed": False
}
data["tasks"].append(task)
save_data(data)
print(f"Task '{name}' added to project '{project}' successfully.")
task.list:
params: [project: ProjectName]
run: |
data = load_data()
tasks = data["tasks"]
if project:
tasks = [task for task in tasks if task["project"] == project]
if tasks:
table_data = [
[
task["project"],
task["name"],
format_date(task["due_date"]) if task["due_date"] else "N/A",
task["priority"],
"x" if task["completed"] else "o"
]
for task in tasks
]
headers = ["Project", "Task", "Due Date", "Priority", "Completed"]
print(tabulate(table_data, headers=headers, tablefmt="grid"))
else:
print("No tasks found.")
task.complete:
params: [project: ProjectName, name: TaskName]
run: |
data = load_data()
for task in data["tasks"]:
if task["project"] == project and task["name"] == name:
task["completed"] = True
save_data(data)
print(f"Task '{name}' in project '{project}' marked as completed.")
return
print(f"Task '{name}' in project '{project}' not found.")
task.remove:
params: [project: ProjectName, name: TaskName]
run: |
data = load_data()
data["tasks"] = [task for task in data["tasks"] if task["project"] != project or task["name"] != name]
save_data(data)
print(f"Task '{name}' removed from project '{project}' successfully.")
backup:
help: Create a backup of the task data
run: |
$ cp {{data_file}} {{data_file}}.backup
$ echo "Backup created: {{data_file}}.backup"
tests:
- project add test1: assert result.exit_code == 0
- project list: assert "test1" in result.output
- project add test2: assert result.exit_code == 0
- project list: assert "test1" in result.output and "test2" in result.output
- task add test1 task1: assert result.exit_code == 0
- task add test1 task2: assert result.exit_code == 0
- task list test1: assert "task1" in result.output and "task2" in result.output
- task remove test1 task1: assert "removed" in result.output
- project remove test1: assert "removed" in result.output
- task list test1: assert "No tasks found" in result.output
- $ rm tasks.json