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:
parent
135eabc57c
commit
8267bc2e12
4 changed files with 32 additions and 30 deletions
|
|
@ -10,32 +10,8 @@ readonly NUX_RUNNER=$0;
|
||||||
readonly NUX_RUNNER_BIN_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
|
readonly NUX_RUNNER_BIN_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
|
||||||
source $NUX_RUNNER_BIN_DIR/../inc/nux-base.inc.sh
|
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':
|
## Tasks provided by 'nux-runner':
|
||||||
|
|
||||||
|
|
@ -43,14 +19,14 @@ runner.run() {
|
||||||
## debug - Runs specified task with debug messages enabled.
|
## debug - Runs specified task with debug messages enabled.
|
||||||
task.debug() {
|
task.debug() {
|
||||||
N_LOG_debug=1
|
N_LOG_debug=1
|
||||||
runner.run "$@"
|
nux-runner.run "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
## trace - Runs specified task with debug & trace enabled.
|
## trace - Runs specified task with debug & trace enabled.
|
||||||
task.trace() {
|
task.trace() {
|
||||||
N_LOG_debug=1;
|
N_LOG_debug=1;
|
||||||
N_LOG_trace=2;
|
N_LOG_trace=2;
|
||||||
runner.run "$@"
|
nux-runner.run "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
## help - Shows this help
|
## help - Shows this help
|
||||||
|
|
@ -73,4 +49,4 @@ readonly NUX_SCRIPT=$1;
|
||||||
shift; # Determines script
|
shift; # Determines script
|
||||||
readonly NUX_SCRIPTNAME=$(basename $NUX_SCRIPT)
|
readonly NUX_SCRIPTNAME=$(basename $NUX_SCRIPT)
|
||||||
|
|
||||||
runner.run "$@"
|
nux-runner.run "$@"
|
||||||
|
|
|
||||||
|
|
@ -54,3 +54,8 @@ function nux.include {
|
||||||
local incfile="$1.inc.sh"
|
local incfile="$1.inc.sh"
|
||||||
source "$NUX_INC_DIR/$incfile"
|
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
21
inc/nux-runner.inc.sh
Normal 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
|
||||||
|
}
|
||||||
|
|
@ -5,12 +5,12 @@ function exec.if.function {
|
||||||
DEFAULT_NAME=$2;
|
DEFAULT_NAME=$2;
|
||||||
shift; shift;
|
shift; shift;
|
||||||
|
|
||||||
if is_function $FUNC_NAME; then
|
if nux.check.function $FUNC_NAME; then
|
||||||
nux.log debug Executing: $FUNC_NAME "$@";
|
nux.log debug Executing: $FUNC_NAME "$@";
|
||||||
$FUNC_NAME "$@";
|
$FUNC_NAME "$@";
|
||||||
return;
|
return;
|
||||||
fi
|
fi
|
||||||
if is_function $DEFAULT_NAME; then
|
if nux.check.function $DEFAULT_NAME; then
|
||||||
nux.log debug Executing: $FUNC_NAME "$@";
|
nux.log debug Executing: $FUNC_NAME "$@";
|
||||||
$DEFAULT_NAME "$@";
|
$DEFAULT_NAME "$@";
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue