Skip to content

Commit cc75251

Browse files
committed
prefix for tasks to avoid conflicts
1 parent cfd0dc9 commit cc75251

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,15 @@ affects the bash completion
186186
usage
187187
* **SODA_DEFAULT_RESOURCE_DIR** - the default directory to search for resources (defaults to
188188
*resources*)
189+
* **SODA_TASK_OPTIONAL_PREFIX** - the optional prefix to map a task function (defaults to *do_*)
189190

190191
Remember that parameters are converted to upper case, so you can call `soda --log-file=path/to/file`
191192
and the *$LOG_FILE* variable will be set to that value.
192193

194+
The parameter **SODA_TASK_OPTIONAL_PREFIX** is very usefull in case of tasks with a name already
195+
defined by another function or name (*kill* or *status*, for example). To avoid conflicts, prefix
196+
the function with the SODA_TASK_OPTIONAL_PREFIX value (*do_kill*, *do_status*, ...).
197+
193198
## Logging
194199

195200
To log something, just call the **log** function passing the category and message (optionally, you

config/soda/conventions.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@
2424
SODA_NAMESPACE_DELIMITER=.
2525
SODA_TASK_BASH_COMPLETION_SUFFIX=_bash_completion
2626
SODA_DEFAULT_RESOURCE_DIR=resources
27+
SODA_TASK_OPTIONAL_PREFIX=do_

scripts/soda/exec.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,21 @@ execute() {
128128
}
129129

130130
#
131-
# Calls the given function. Using this method will broadcast events around the call:
131+
# Calls the given task. Using this method will broadcast events around the call:
132132
#
133-
# ${FUNCTION_NAME}-start: after call
134-
# ${FUNCTION_NAME}-finish: before call
133+
# ${TASK_NAME}-start: after call
134+
# ${TASK_NAME}-finish: before call
135135
#
136-
# This method is intented to use for task call
136+
# ** This method is intented to use for task call **
137137
#
138138
call() {
139139
local function_name="$(build_name $1)"
140+
local task_name="$1"
140141
shift
141-
broadcast "${function_name}-start"
142+
broadcast "${task_name}-start"
143+
if [[ $(type -t ${SODA_TASK_OPTIONAL_PREFIX}${function_name}) ]]; then
144+
function_name="${SODA_TASK_OPTIONAL_PREFIX}${function_name}"
145+
fi
142146
$function_name "$@"
143-
broadcast "${function_name}-finish"
147+
broadcast "${task_name}-finish"
144148
}

0 commit comments

Comments
 (0)