mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
Refactored some common functions to nux-base.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
b0bf4b6679
commit
6e5c5986c3
3 changed files with 68 additions and 40 deletions
|
|
@ -6,14 +6,9 @@
|
|||
### (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
|
||||
source $NUX_RUNNER_BIN_DIR/../inc/nux-base.inc.sh
|
||||
|
||||
|
||||
|
||||
|
|
@ -22,21 +17,17 @@ function is_function () {
|
|||
return 1
|
||||
}
|
||||
|
||||
log.debug() {
|
||||
:
|
||||
}
|
||||
|
||||
runner.run() {
|
||||
TASK=$1; shift; # Determines task
|
||||
if is_function task.$TASK ; then
|
||||
log.debug "Running task: $TASK";
|
||||
nux.log debug "Running task: $TASK";
|
||||
task.$TASK "$@" # Runs task
|
||||
else
|
||||
log.debug "Including script: $NUX_SCRIPT"
|
||||
nux.log debug "Including script: $NUX_SCRIPT"
|
||||
source $NUX_SCRIPT; # Includes script
|
||||
|
||||
if is_function task.$TASK ; then
|
||||
log.debug "Running task: $TASK";
|
||||
nux.log debug "Running task: $TASK";
|
||||
task.$TASK "$@" # Runs task
|
||||
else
|
||||
echo "$NUX_SCRIPTNAME: Unrecognized task ''$TASK' not available."
|
||||
|
|
@ -45,16 +36,20 @@ runner.run() {
|
|||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
##
|
||||
## Tasks provided by 'nux-runner':
|
||||
|
||||
|
||||
## debug - Runs specified task with debug messages enabled.
|
||||
task.debug() {
|
||||
log.debug() {
|
||||
echo -e "${NC_Debug}[DEBUG] $@ ${NC_No}" >&2
|
||||
}
|
||||
N_LOG_debug=1
|
||||
runner.run "$@"
|
||||
}
|
||||
|
||||
## trace - Runs specified task with debug & trace enabled.
|
||||
task.trace() {
|
||||
N_LOG_debug=1;
|
||||
N_LOG_trace=2;
|
||||
runner.run "$@"
|
||||
}
|
||||
|
||||
|
|
|
|||
56
inc/nux-base.inc.sh
Normal file
56
inc/nux-base.inc.sh
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
|
||||
readonly NUX_INC_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
|
||||
|
||||
# Color defintions
|
||||
|
||||
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'
|
||||
|
||||
# Color for message levels
|
||||
NC_info=$NC_LightGray
|
||||
NC_error=$NC_LightRed
|
||||
NC_warning=$NC_Yellow
|
||||
NC_debug=$NC_White
|
||||
|
||||
N_LOG_info=1
|
||||
N_LOG_error=2
|
||||
N_LOG_warning=3
|
||||
|
||||
function nux.log {
|
||||
local level=$1
|
||||
local color=NC_$level
|
||||
local setting=N_LOG_$level
|
||||
shift;
|
||||
if [ ! -z ${!setting+x} ]; then
|
||||
echo -e "${!color}[$level]$NC_No $*$NC_No" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
function nux.echo.error {
|
||||
echo -e "${NC_error}$* ${NC_No}";
|
||||
}
|
||||
|
||||
function nux.echo.warning {
|
||||
echo -e "${NC_warning}$* ${NC_No}";
|
||||
}
|
||||
|
||||
|
||||
function nux.include {
|
||||
local incfile="$1.inc.sh"
|
||||
source "$NUX_INC_DIR/$incfile"
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
|
||||
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