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:
parent
76ae7c20f7
commit
9aa2386987
2 changed files with 55 additions and 20 deletions
|
|
@ -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 "$@"
|
||||
|
|
|
|||
23
inc/nux-base.sh
Normal file
23
inc/nux-base.sh
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
readonly NC_No='\033[0m' # No Color
|
||||
readonly NC_Black='\033[0;30m'
|
||||
readonly NC_Green='\033[0;32m'
|
||||
readonly NC_Red='\033[0;31m'
|
||||
readonly NC_BrownOrange='\033[0;33m'
|
||||
readonly NC_Blue='\033[0;34m'
|
||||
readonly NC_Purple='\033[0;35m'
|
||||
readonly NC_Cyan='\033[0;36m'
|
||||
readonly NC_LightGray='\033[0;37m'
|
||||
|
||||
readonly NC_DarkGray='\033[1;30m'
|
||||
readonly NC_LightRed='\033[1;31m'
|
||||
readonly NC_LightGreen='\033[1;32m'
|
||||
readonly NC_Yellow='\033[1;33m'
|
||||
readonly NC_LightBlue='\033[1;34m'
|
||||
readonly NC_LightPurple='\033[1;35m'
|
||||
readonly NC_LightCyan='\033[1;36m'
|
||||
readonly NC_White='\033[1;37m'
|
||||
|
||||
NC_Debug=$NC_LightGray
|
||||
NC_Error=$NC_LightRed
|
||||
NC_Warning=$NC_Yellow
|
||||
Loading…
Add table
Add a link
Reference in a new issue