Skip to content

Commit

Permalink
Added status messages for listaddons and file test (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysle authored Dec 26, 2024
1 parent 8afcc36 commit 0e7c091
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/t8010-listaddons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ This test checks listing of custom actions.

test_todo_session 'no custom actions' <<EOF
>>> todo.sh listaddons
TODO: '$TODO_ACTIONS_DIR' does not exist.
=== 1
EOF

make_action "foo"
test_todo_session 'one custom action' <<EOF
>>> todo.sh listaddons
foo
--
TODO: 1 valid addon actions found.
EOF

make_action "bar"
Expand All @@ -26,6 +30,8 @@ bar
foo
ls
quux
--
TODO: 4 valid addon actions found.
EOF

invalidate_action .todo.actions.d/foo t8010.4
Expand All @@ -34,6 +40,8 @@ test_todo_session 'nonexecutable action' <<EOF
bar
ls
quux
--
TODO: 3 valid addon actions found.
EOF

make_action_in_folder "chuck"
Expand All @@ -59,6 +67,8 @@ chuck
ls
norris
quux
--
TODO: 5 valid addon actions found.
EOF

invalidate_action .todo.actions.d/norris/norris t8010.8
Expand All @@ -68,6 +78,8 @@ bar
chuck
ls
quux
--
TODO: 4 valid addon actions found.
EOF

test_done
16 changes: 15 additions & 1 deletion todo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ dieWithHelp()

die "$@"
}

die()
{
echo >&2 "$*"
Expand Down Expand Up @@ -878,7 +879,7 @@ _list() {
local FILE="$1"
## If the file starts with a "/" use absolute path. Otherwise,
## try to find it in either $TODO_DIR or using a relative path
if [ "${1:0:1}" == / ]; then
if [ "${1:0:1}" == / ] && [ -f "$FILE" ]; then
## Absolute path
src="$FILE"
elif [ -f "$TODO_DIR/$FILE" ]; then
Expand Down Expand Up @@ -1523,14 +1524,27 @@ note: PRIORITY must be anywhere from A to Z."
"listaddons" )
if [ -d "$TODO_ACTIONS_DIR" ]; then
cd "$TODO_ACTIONS_DIR" || exit $?
actionsCnt=0
for action in *
do
if [ -f "$action" ] && [ -x "$action" ]; then
echo "$action"
((actionsCnt+=1))
elif [ -d "$action" ] && [ -x "$action/$action" ]; then
echo "$action"
((actionsCnt+=1))
fi
done
if ! [ "$actionsCnt" -gt 0 ]; then
die "TODO: '$TODO_ACTIONS_DIR' does not contain valid actions."
else
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
echo "--"
echo "TODO: $actionsCnt valid addon actions found."
fi
fi
else
die "TODO: '$TODO_ACTIONS_DIR' does not exist."
fi
;;

Expand Down

0 comments on commit 0e7c091

Please sign in to comment.