1
1
Fork 0
mirror of https://github.com/tonydamage/nux-env.git synced 2025-12-11 13:24:28 +01:00

Splitted part of nux-ranner into include script.

Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
Tony Tkáčik 2016-11-11 17:18:54 +01:00
parent 76ae7c20f7
commit 9aa2386987
2 changed files with 55 additions and 20 deletions

View file

@ -5,6 +5,18 @@
### and provides out of the box support for task-style scripts
### (similar in usage such as apt, git).
###
# .---------- constant part!
# vvvv vvvv-- the code from above
readonly NUX_RUNNER=$0;
readonly NUX_RUNNER_BIN_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
source $NUX_RUNNER_BIN_DIR/../inc/nux-base.sh
function is_function () {
declare -f "$1" &>/dev/null && return 0
return 1
@ -14,21 +26,21 @@ log.debug() {
:
}
run_task() {
runner.run() {
TASK=$1; shift; # Determines task
if is_function task_$TASK ; then
if is_function task.$TASK ; then
log.debug "Running task: $TASK";
task_$TASK "$*" # Runs task
task.$TASK "$@" # Runs task
else
log.debug "Including script: $NUX_SCRIPT"
source $NUX_SCRIPT; # Includes script
if is_function task_$TASK ; then
if is_function task.$TASK ; then
log.debug "Running task: $TASK";
task_$TASK "$*" # Runs task
task.$TASK "$@" # Runs task
else
echo "$SCRIPTNAME: Unrecognized task ''$TASK' not available."
echo "Try '$SCRIPTNAME help' for more information."
echo "$NUX_SCRIPTNAME: Unrecognized task ''$TASK' not available."
echo "Try '$NUX_SCRIPTNAME help' for more information."
exit -1
fi
fi
@ -39,31 +51,31 @@ run_task() {
## debug - Runs specified task with debug messages enabled.
task_debug() {
task.debug() {
log.debug() {
echo "[DEBUG] $*" >&2
echo -e "${NC_Debug}[DEBUG] $@ ${NC_No}" >&2
}
run_task "$*"
runner.run "$@"
}
## help - Shows this help
task_help() {
echo Usage: $SCRIPTNAME [task] [options]
grep "^\#\#\#" $NUX_SCRIPT | cut -d\# -f4-
task.help() {
echo Usage: $NUX_SCRIPTNAME [task] [options]
grep "^\#\#\# " $NUX_SCRIPT | cut -d\# -f4-
echo " Available Tasks: "
grep "^\#\# " $NUX_SCRIPT | cut -d\# -f3-
grep "^\#\#" $NUX_RUNNER | cut -d\# -f3-
grep "^\#\# " $NUX_RUNNER | cut -d\# -f3-
echo
}
##
task_() {
task_help
task.() {
task.help
}
NUX_RUNNER=$0;
NUX_SCRIPT=$1; shift; # Determines script
SCRIPTNAME=$(basename $NUX_SCRIPT)
readonly NUX_SCRIPT=$1;
shift; # Determines script
readonly NUX_SCRIPTNAME=$(basename $NUX_SCRIPT)
run_task "$*"
runner.run "$@"