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

Moved is_function and runner.run to inc/

Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
Tony Tkáčik 2016-11-11 20:09:30 +01:00
parent 135eabc57c
commit 8267bc2e12
4 changed files with 32 additions and 30 deletions

View file

@ -10,32 +10,8 @@ readonly NUX_RUNNER=$0;
readonly NUX_RUNNER_BIN_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
source $NUX_RUNNER_BIN_DIR/../inc/nux-base.inc.sh
nux.include nux-runner
function is_function () {
declare -f "$1" &>/dev/null && return 0
return 1
}
runner.run() {
TASK=$1; shift; # Determines task
if is_function task.$TASK ; then
nux.log debug "Running task: $TASK";
task.$TASK "$@" # Runs task
else
nux.log debug "Including script: $NUX_SCRIPT"
source $NUX_SCRIPT; # Includes script
if is_function task.$TASK ; then
nux.log debug "Running task: $TASK";
task.$TASK "$@" # Runs task
else
echo "$NUX_SCRIPTNAME: Unrecognized task ''$TASK' not available."
echo "Try '$NUX_SCRIPTNAME help' for more information."
exit -1
fi
fi
}
##
## Tasks provided by 'nux-runner':
@ -43,14 +19,14 @@ runner.run() {
## debug - Runs specified task with debug messages enabled.
task.debug() {
N_LOG_debug=1
runner.run "$@"
nux-runner.run "$@"
}
## trace - Runs specified task with debug & trace enabled.
task.trace() {
N_LOG_debug=1;
N_LOG_trace=2;
runner.run "$@"
nux-runner.run "$@"
}
## help - Shows this help
@ -73,4 +49,4 @@ readonly NUX_SCRIPT=$1;
shift; # Determines script
readonly NUX_SCRIPTNAME=$(basename $NUX_SCRIPT)
runner.run "$@"
nux-runner.run "$@"

View file

@ -54,3 +54,8 @@ function nux.include {
local incfile="$1.inc.sh"
source "$NUX_INC_DIR/$incfile"
}
function nux.check.function {
declare -f "$1" &>/dev/null && return 0
return 1
}

21
inc/nux-runner.inc.sh Normal file
View file

@ -0,0 +1,21 @@
nux-runner.run() {
TASK=$1; shift; # Determines task
if nux.check.function task.$TASK ; then
nux.log debug "Running task: $TASK";
task.$TASK "$@" # Runs task
else
nux.log debug "Including script: $NUX_SCRIPT"
source $NUX_SCRIPT; # Includes script
if nux.check.function task.$TASK ; then
nux.log debug "Running task: $TASK";
task.$TASK "$@" # Runs task
else
echo "$NUX_SCRIPTNAME: Unrecognized task ''$TASK' not available."
echo "Try '$NUX_SCRIPTNAME help' for more information."
exit -1
fi
fi
}

View file

@ -5,12 +5,12 @@ function exec.if.function {
DEFAULT_NAME=$2;
shift; shift;
if is_function $FUNC_NAME; then
if nux.check.function $FUNC_NAME; then
nux.log debug Executing: $FUNC_NAME "$@";
$FUNC_NAME "$@";
return;
fi
if is_function $DEFAULT_NAME; then
if nux.check.function $DEFAULT_NAME; then
nux.log debug Executing: $FUNC_NAME "$@";
$DEFAULT_NAME "$@";
return;