Use die() / print to stderr for error conditions

To indicate that something went wrong (e.g. the task already was unprioritized).
Note: For actions that handle multiple ITEMs in a loop, we cannot use die() as that would abort processing of any following ITEM(s). Instead, use a status variable and set it to 1 on error, then exit at the end.
This commit is contained in:
Ingo Karkat
2023-01-21 19:01:24 +01:00
parent 803881998f
commit ef419f3594
7 changed files with 26 additions and 10 deletions

View File

@@ -90,6 +90,7 @@ TODO: 2 re-prioritized from (C) to (A).
TODO: 3 of 3 tasks shown
>>> todo.sh pri 2 a
=== 1
2 (A) notice the sunflowers
TODO: 2 already prioritized (A).

View File

@@ -81,6 +81,7 @@ test_todo_session 'fail multiple do attempts' <<EOF
TODO: 3 marked as done.
>>> todo.sh -a do 3
=== 1
TODO: 3 is already marked done.
EOF

View File

@@ -82,6 +82,7 @@ test_todo_session 'depriority of unprioritized task' <<EOF
TODO: 3 of 3 tasks shown
>>> todo.sh depri 3 2
=== 1
TODO: 3 is not prioritized.
2 notice the sunflowers
TODO: 2 deprioritized.

View File

@@ -60,6 +60,7 @@ test_todo_session 'del with confirmation' <<EOF
TODO: 3 of 3 tasks shown
>>> printf n | todo.sh del 1
=== 1
Delete '(B) smell the uppercase Roses +flowers @outside'? (y/n)$SPACE
TODO: No tasks were deleted.
@@ -71,10 +72,12 @@ TODO: No tasks were deleted.
TODO: 3 of 3 tasks shown
>>> printf x | todo.sh del 1
=== 1
Delete '(B) smell the uppercase Roses +flowers @outside'? (y/n)$SPACE
TODO: No tasks were deleted.
>>> echo | todo.sh del 1
=== 1
Delete '(B) smell the uppercase Roses +flowers @outside'? (y/n)$SPACE
TODO: No tasks were deleted.

View File

@@ -32,6 +32,7 @@ EOF
test_todo_session 'deduplicate without duplicates' <<EOF
>>> todo.sh deduplicate
=== 1
TODO: No duplicate tasks found
EOF

View File

@@ -47,7 +47,7 @@ echo 'export TODO_ACTIONS_DIR=$HOME/custom.actions' >> custom.cfg
export TODOTXT_GLOBAL_CFG_FILE=global.cfg
test_todo_session '-h and fatal error without config' <<EOF
>>> todo.sh -h | sed '/^ \\{0,2\\}[A-Z]/!d'
>>> todo.sh -h 2>&1 | sed '/^ \\{0,2\\}[A-Z]/!d'
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
Actions:
Actions can be added and overridden using scripts in the actions
@@ -58,7 +58,7 @@ EOF
# Config option comes too late; "Add-on Actions" is *not* mentioned here.
test_todo_session '-h and fatal error with trailing custom config' <<EOF
>>> todo.sh -h -d custom.cfg | sed '/^ \\{0,2\\}[A-Z]/!d'
>>> todo.sh -h -d custom.cfg 2>&1 | sed '/^ \\{0,2\\}[A-Z]/!d'
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
Actions:
Actions can be added and overridden using scripts in the actions
@@ -69,7 +69,7 @@ EOF
# Config option processed; "Add-on Actions" is mentioned here.
test_todo_session '-h output with preceding custom config' <<EOF
>>> todo.sh -d custom.cfg -h | sed '/^ \\{0,2\\}[A-Z]/!d'
>>> todo.sh -d custom.cfg -h 2>&1 | sed '/^ \\{0,2\\}[A-Z]/!d'
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
Actions:
Actions can be added and overridden using scripts in the actions