Skip to content

Commit ecae92f

Browse files
committed
Address code review feedback: rename addp to addpri|ap and improve implementation
- Rename command from 'addp' to 'addpri|ap' to match existing patterns (add|a, pri|p) - Replace grep-based priority validation with modern Bash syntax - Update shorthelp() and actionsHelp() functions to show both command forms - Update USAGE.md documentation to reflect new command name - Replace dynamic date with hardcoded 2009-02-13 in tests per framework requirements - Rename test file from t1050-addp.sh to t1050-addpri.sh for consistency - Update all test references from addp to addpri throughout test suite
1 parent 033f5de commit ecae92f

File tree

3 files changed

+47
-46
lines changed

3 files changed

+47
-46
lines changed

USAGE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ todo.sh addm "FIRST THING I NEED TO DO +project1 @context
2828
SECOND THING I NEED TO DO +project2 @context"
2929
```
3030

31-
### `addp`
31+
### `addpri`
3232
Adds TEXT TO ADD to your todo.txt file on its own line with the specified PRIORITY (A-Z) at the beginning.
3333

3434
The priority letter is automatically converted to uppercase and formatted as `(PRIORITY)`.
3535

3636
```shell
37-
todo.sh addp A "Important high-priority task"
38-
todo.sh addp e "Medium priority task"
37+
todo.sh addpri A "Important high-priority task"
38+
todo.sh ap E "Medium priority task"
3939
```
4040

4141
Example output:

tests/t1050-addp.sh renamed to tests/t1050-addpri.sh

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#!/usr/bin/env bash
22

3-
test_description='addp command functionality
3+
test_description='addpri command functionality
44
5-
Tests the addp command which adds tasks with specified priority.
5+
Tests the addpri command which adds tasks with specified priority.
66
'
77
. ./test-lib.sh
88

9-
# Test basic addp functionality
10-
test_todo_session 'basic addp functionality' <<EOF
11-
>>> todo.sh addp A "High priority task"
9+
# Test basic addpri functionality
10+
test_todo_session 'basic addpri functionality' <<EOF
11+
>>> todo.sh addpri A "High priority task"
1212
1 (A) High priority task
1313
TODO: 1 added.
1414
15-
>>> todo.sh addp B "Medium priority task"
15+
>>> todo.sh addpri B "Medium priority task"
1616
2 (B) Medium priority task
1717
TODO: 2 added.
1818
19-
>>> todo.sh addp Z "Low priority task"
19+
>>> todo.sh addpri Z "Low priority task"
2020
3 (Z) Low priority task
2121
TODO: 3 added.
2222
@@ -32,11 +32,11 @@ EOF
3232
cat > todo.txt <<EOF
3333
EOF
3434
test_todo_session 'lowercase priority conversion' <<EOF
35-
>>> todo.sh addp c "lowercase priority test"
35+
>>> todo.sh addpri c "lowercase priority test"
3636
1 (C) lowercase priority test
3737
TODO: 1 added.
3838
39-
>>> todo.sh addp z "another lowercase test"
39+
>>> todo.sh addpri z "another lowercase test"
4040
2 (Z) another lowercase test
4141
TODO: 2 added.
4242
@@ -47,15 +47,15 @@ TODO: 2 added.
4747
TODO: 2 of 2 tasks shown
4848
EOF
4949

50-
# Test addp with projects and contexts
50+
# Test addpri with projects and contexts
5151
cat > todo.txt <<EOF
5252
EOF
53-
test_todo_session 'addp with projects and contexts' <<EOF
54-
>>> todo.sh addp A "Important work task +project @work"
53+
test_todo_session 'addpri with projects and contexts' <<EOF
54+
>>> todo.sh addpri A "Important work task +project @work"
5555
1 (A) Important work task +project @work
5656
TODO: 1 added.
5757
58-
>>> todo.sh addp B "Call client +client @phone"
58+
>>> todo.sh addpri B "Call client +client @phone"
5959
2 (B) Call client +client @phone
6060
TODO: 2 added.
6161
@@ -69,66 +69,66 @@ EOF
6969
# Test error handling - no arguments
7070
cat > todo.txt <<EOF
7171
EOF
72-
test_todo_session 'addp error - no arguments' <<EOF
73-
>>> todo.sh addp
74-
usage: todo.sh addp PRIORITY "TODO ITEM"
72+
test_todo_session 'addpri error - no arguments' <<EOF
73+
>>> todo.sh addpri
74+
usage: todo.sh addpri PRIORITY "TODO ITEM"
7575
=== 1
7676
EOF
7777

7878
# Test error handling - missing task text
79-
test_todo_session 'addp error - missing task text' <<EOF
80-
>>> todo.sh addp A
81-
usage: todo.sh addp PRIORITY "TODO ITEM"
79+
test_todo_session 'addpri error - missing task text' <<EOF
80+
>>> todo.sh addpri A
81+
usage: todo.sh addpri PRIORITY "TODO ITEM"
8282
=== 1
8383
EOF
8484

8585
# Test error handling - invalid priority (number)
86-
test_todo_session 'addp error - invalid priority number' <<EOF
87-
>>> todo.sh addp 1 "Invalid priority task"
86+
test_todo_session 'addpri error - invalid priority number' <<EOF
87+
>>> todo.sh addpri 1 "Invalid priority task"
8888
TODO: Priority must be a letter from A to Z (got: 1)
8989
=== 1
9090
EOF
9191

9292
# Test error handling - invalid priority (multiple characters)
93-
test_todo_session 'addp error - invalid priority multiple chars' <<EOF
94-
>>> todo.sh addp AA "Invalid priority task"
93+
test_todo_session 'addpri error - invalid priority multiple chars' <<EOF
94+
>>> todo.sh addpri AA "Invalid priority task"
9595
TODO: Priority must be a letter from A to Z (got: AA)
9696
=== 1
9797
EOF
9898

9999
# Test error handling - invalid priority (special character)
100-
test_todo_session 'addp error - invalid priority special char' <<EOF
101-
>>> todo.sh addp @ "Invalid priority task"
100+
test_todo_session 'addpri error - invalid priority special char' <<EOF
101+
>>> todo.sh addpri @ "Invalid priority task"
102102
TODO: Priority must be a letter from A to Z (got: @)
103103
=== 1
104104
EOF
105105

106-
# Test addp integration with date_on_add
106+
# Test addpri integration with date_on_add
107107
cat > todo.txt <<EOF
108108
EOF
109109
echo "export TODOTXT_DATE_ON_ADD=1" >> todo.cfg
110110

111-
test_todo_session 'addp with date on add' <<EOF
112-
>>> todo.sh addp A "Task with date"
113-
1 (A) $(date '+%Y-%m-%d') Task with date
111+
test_todo_session 'addpri with date on add' <<EOF
112+
>>> todo.sh addpri A "Task with date"
113+
1 (A) 2009-02-13 Task with date
114114
TODO: 1 added.
115115
116116
>>> todo.sh -p list
117-
1 (A) $(date '+%Y-%m-%d') Task with date
117+
1 (A) 2009-02-13 Task with date
118118
--
119119
TODO: 1 of 1 tasks shown
120120
EOF
121121

122122
# Reset config for next test
123123
echo "export TODOTXT_DATE_ON_ADD=0" >> todo.cfg
124124

125-
# Test that addp overrides TODOTXT_PRIORITY_ON_ADD
125+
# Test that addpri overrides TODOTXT_PRIORITY_ON_ADD
126126
cat > todo.txt <<EOF
127127
EOF
128128
echo "export TODOTXT_PRIORITY_ON_ADD=C" >> todo.cfg
129129

130-
test_todo_session 'addp overrides PRIORITY_ON_ADD' <<EOF
131-
>>> todo.sh addp A "Priority A task"
130+
test_todo_session 'addpri overrides PRIORITY_ON_ADD' <<EOF
131+
>>> todo.sh addpri A "Priority A task"
132132
1 (A) Priority A task
133133
TODO: 1 added.
134134
@@ -143,15 +143,15 @@ TODO: 2 added.
143143
TODO: 2 of 2 tasks shown
144144
EOF
145145

146-
# Test addp with various edge cases
146+
# Test addpri with various edge cases
147147
cat > todo.txt <<EOF
148148
EOF
149-
test_todo_session 'addp edge cases' <<EOF
150-
>>> todo.sh addp E "Task with special chars: !@#$%^&*()"
149+
test_todo_session 'addpri edge cases' <<EOF
150+
>>> todo.sh addpri E "Task with special chars: !@#$%^&*()"
151151
1 (E) Task with special chars: !@#$%^&*()
152152
TODO: 1 added.
153153
154-
>>> todo.sh addp F "Task with 'single quotes' and \"double quotes\""
154+
>>> todo.sh addpri F "Task with 'single quotes' and \"double quotes\""
155155
2 (F) Task with 'single quotes' and "double quotes"
156156
TODO: 2 added.
157157

todo.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ shorthelp()
4545
add|a "THING I NEED TO DO +project @context"
4646
addm "THINGS I NEED TO DO
4747
MORE THINGS I NEED TO DO"
48-
addp PRIORITY "TEXT TO ADD"
48+
addpri|ap PRIORITY "TEXT TO ADD"
4949
addto DEST "TEXT TO ADD"
5050
append|app NR "TEXT TO APPEND"
5151
archive
@@ -178,10 +178,11 @@ actionsHelp()
178178
Adds SECOND THING I NEED TO DO to you todo.txt on its own line.
179179
Project and context notation optional.
180180
181-
addp PRIORITY "TEXT TO ADD"
181+
addpri PRIORITY "TEXT TO ADD"
182+
ap PRIORITY "TEXT TO ADD"
182183
Adds TEXT TO ADD to your todo.txt file on its own line with
183184
the specified PRIORITY (A-Z) at the beginning.
184-
For example, addp A "Important task" creates "(A) Important task".
185+
For example, addpri A "Important task" creates "(A) Important task".
185186
186187
addto DEST "TEXT TO ADD"
187188
Adds a line of text to any file located in the todo.txt directory.
@@ -1126,14 +1127,14 @@ case $action in
11261127
IFS=$SAVEIFS
11271128
;;
11281129

1129-
"addp")
1130-
errmsg="usage: $TODO_SH addp PRIORITY \"TODO ITEM\""
1130+
"addpri" | "ap")
1131+
errmsg="usage: $TODO_SH addpri PRIORITY \"TODO ITEM\""
11311132
[ -z "$2" ] && die "$errmsg"
11321133
priority="$2"
11331134
[ -z "$3" ] && die "$errmsg"
11341135

11351136
# Validate priority is a single letter A-Z
1136-
if ! echo "$priority" | grep -q '^[A-Za-z]$'; then
1137+
if [[ "$priority" != @([A-Za-z]) ]]; then
11371138
die "TODO: Priority must be a letter from A to Z (got: $priority)"
11381139
fi
11391140

0 commit comments

Comments
 (0)