Tests: Refactoring: Extract make_dummy_action()

The action script creation in both test helper functions is pretty similar; extract a function for that so that the invocation is a single command.
This commit is contained in:
Ingo Karkat
2021-09-16 19:44:48 +02:00
parent 2d70a0aadf
commit 7792006853

View File

@@ -1,20 +1,26 @@
#!/bin/bash
make_dummy_action()
{
local actionName; actionName="$(basename "${1:?}")"
cat > "$1" <<EOF
#!/bin/bash
[ "\$1" = "usage" ] && {
echo " $actionName ITEM#[, ITEM#, ...] [TERM...]"
echo " This custom action does $actionName."
echo ""
exit
}
echo "custom action $actionName$2"
EOF
chmod +x "$1"
}
make_action()
{
unset TODO_ACTIONS_DIR
[ -d .todo.actions.d ] || mkdir .todo.actions.d
cat > ".todo.actions.d/$1" <<EOF
#!/bin/bash
[ "\$1" = "usage" ] && {
echo " $1 ITEM#[, ITEM#, ...] [TERM...]"
echo " This custom action does $1."
echo ""
exit
}
echo "custom action $1"
EOF
chmod +x ".todo.actions.d/$1"
make_dummy_action ".todo.actions.d/$1"
}
make_action_in_folder()
@@ -22,15 +28,5 @@ make_action_in_folder()
unset TODO_ACTIONS_DIR
[ -d .todo.actions.d ] || mkdir .todo.actions.d
mkdir ".todo.actions.d/$1"
cat > ".todo.actions.d/$1/$1" <<EOF
#!/bin/bash
[ "\$1" = "usage" ] && {
echo " $1 ITEM#[, ITEM#, ...] [TERM...]"
echo " This custom action does $1."
echo ""
exit
}
echo "custom action $1 in folder $1"
EOF
chmod +x ".todo.actions.d/$1/$1"
make_dummy_action ".todo.actions.d/$1/$1" "in folder $1"
}