forked from HashSlap-Summer-of-Code/task-trek
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasktrek
More file actions
127 lines (103 loc) · 2.71 KB
/
tasktrek
File metadata and controls
127 lines (103 loc) · 2.71 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
#!/bin/bash
# TaskTrek - Recurring Task Management System
# Main executable script
set -e
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Source the library
source "$SCRIPT_DIR/tasktrek-lib.sh"
# Initialize data directory and file
init_tasktrek() {
mkdir -p "$SCRIPT_DIR/data"
if [[ ! -f "$TASKS_FILE" ]]; then
echo '{"tasks": [], "next_id": 1}' > "$TASKS_FILE"
fi
}
# Usage function
usage() {
cat << EOF
TaskTrek - Recurring Task Management System
Usage: $0 <command> [options]
Commands:
add <title> [description] [--recur <frequency>]
Add a new task. Frequency: daily, weekly, monthly
list [--all]
List pending tasks (--all shows completed too)
complete <id>
Mark task as complete (regenerates if recurring)
delete <id>
Delete a task permanently
help
Show this help message
Examples:
$0 add "Daily standup" "Team meeting" --recur daily
$0 add "Weekly review" --recur weekly
$0 list
$0 complete 1
$0 delete 2
EOF
}
# Parse command line arguments
case "${1:-}" in
"add")
shift
title="$1"
description="${2:-}"
recur_freq=""
# Parse remaining arguments for --recur flag
shift
if [[ "${1:-}" != "" ]]; then
if [[ "$1" != "--recur" ]]; then
description="$1"
shift
fi
fi
if [[ "${1:-}" == "--recur" ]]; then
recur_freq="${2:-}"
if [[ ! "$recur_freq" =~ ^(daily|weekly|monthly)$ ]]; then
echo "Error: Invalid recurrence frequency. Use: daily, weekly, monthly"
exit 1
fi
fi
if [[ -z "$title" ]]; then
echo "Error: Task title is required"
usage
exit 1
fi
add_task "$title" "$description" "$recur_freq"
;;
"list")
regenerate_recurring_tasks
show_all="false"
if [[ "${2:-}" == "--all" ]]; then
show_all="true"
fi
list_tasks "$show_all"
;;
"complete")
task_id="${2:-}"
if [[ -z "$task_id" ]]; then
echo "Error: Task ID is required"
usage
exit 1
fi
complete_task "$task_id"
;;
"delete")
task_id="${2:-}"
if [[ -z "$task_id" ]]; then
echo "Error: Task ID is required"
usage
exit 1
fi
delete_task "$task_id"
;;
"help"|"--help"|"-h")
usage
;;
*)
echo "Error: Unknown command '${1:-}'"
usage
exit 1
;;
esac