introduce --verbosity flag rather than mixed logging settings; correct color misnaming to ANSI convention; added sanity-check; simplified hello-world; created FZF_USER_INPUT to replace the confusing FZF_HEAD and FZF_TAIL
This commit is contained in:
45
run
45
run
@ -18,9 +18,13 @@ __RUN() {
|
||||
runtime
|
||||
-y, --yes auto-accept all [yn] prompts through current scwrypt
|
||||
-e, --env <env-name> set environment; overwrites SCWRYPTS_ENV
|
||||
-q, --quiet run in quiet mode
|
||||
-n, --no-log skip the log file and run in quiet mode
|
||||
-v, --verbose override quiet mode settings and print all debug dialogue
|
||||
-n shorthand for "--verbosity 0"
|
||||
-v, --verbosity [0-4] set scwrypts log level to one of the following:
|
||||
0 : only command output and critical failures; skips logfile
|
||||
1 : add success / failure messages
|
||||
2 : (default) include status update messages
|
||||
3 : include warning messages
|
||||
4 : include debug messages
|
||||
|
||||
alternate commands
|
||||
-h, --help display this message and exit
|
||||
@ -44,9 +48,9 @@ __RUN() {
|
||||
local VARSPLIT SEARCH_GROUP SEARCH_TYPE SEARCH_NAME
|
||||
|
||||
local ALLOW_LOGFILE=1
|
||||
local VERBOSE=1
|
||||
local SCWRYPTS_LOG_LEVEL=2
|
||||
|
||||
[ $CI ] && [ ! $SCWRYPTS_CI_FORCE_NON_VERBOSE ] && VERBOSE=2
|
||||
[ $CI ] && [ ! $SCWRYPTS_CI_FORCE_NON_VERBOSE ] && SCWRYPTS_LOG_LEVEL=3
|
||||
|
||||
local ERROR=0
|
||||
|
||||
@ -108,9 +112,8 @@ __RUN() {
|
||||
;;
|
||||
|
||||
-y | --yes ) export __SCWRYPTS_YES=1 ;;
|
||||
-q | --quiet ) VERBOSE=0 ;;
|
||||
-n | --no-log ) VERBOSE=0 ; [ ! $SUBSCWRYPT ] && SUBSCWRYPT=0 ;;
|
||||
-v | --verbose ) VERBOSE=2 ;;
|
||||
-n | --no-log ) SCWRYPTS_LOG_LEVEL=0 ;;
|
||||
-v | --verbosity ) SCWRYPTS_LOG_LEVEL=$2 ;;
|
||||
|
||||
-e | --env )
|
||||
[ ! $2 ] && ERROR "missing value for argument $1" && break
|
||||
@ -210,7 +213,6 @@ __RUN() {
|
||||
|
||||
[[ $(echo $SCWRYPTS_AVAILABLE | wc -l) -eq 2 ]] && {
|
||||
SCWRYPT_SELECTION=$(echo $SCWRYPTS_AVAILABLE | tail -n1)
|
||||
[[ $VERBOSE -eq 2 ]] || VERBOSE=0
|
||||
} || {
|
||||
SCWRYPT_SELECTION=$(echo $SCWRYPTS_AVAILABLE | FZF "select a script to run" --header-lines 1)
|
||||
}
|
||||
@ -271,12 +273,13 @@ __RUN() {
|
||||
local LOGFILE=$(__GET_LOGFILE)
|
||||
|
||||
local HEADER=$(
|
||||
[[ $VERBOSE -gt 0 ]] || return 0
|
||||
[[ $SCWRYPTS_LOG_LEVEL -ge 2 ]] || return 0
|
||||
[ $SUBSCWRYPT ] && return 0
|
||||
echo '====================================================================='
|
||||
echo "script : $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME"
|
||||
echo "run at : $(date)"
|
||||
echo "config : $ENV_NAME"
|
||||
echo "script : $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME"
|
||||
echo "run at : $(date)"
|
||||
echo "config : $ENV_NAME"
|
||||
echo "verbosity : $SCWRYPTS_LOG_LEVEL"
|
||||
[ ! $LOGFILE ] && echo '\033[1;33m------------------------------------------\033[0m'
|
||||
)
|
||||
|
||||
@ -291,22 +294,19 @@ __RUN() {
|
||||
}
|
||||
}
|
||||
|
||||
set -o pipefail
|
||||
{
|
||||
[ $HEADER ] && echo $HEADER
|
||||
[[ $VERBOSE -gt 0 ]] && echo '\033[1;33m--- BEGIN OUTPUT -------------------------\033[0m'
|
||||
[[ $SCWRYPTS_LOG_LEVEL -ge 2 ]] && echo '\033[1;33m--- BEGIN OUTPUT -------------------------\033[0m'
|
||||
(eval "$RUN_STRING $(printf "%q " "$@")")
|
||||
EXIT_CODE=$?
|
||||
[[ $VERBOSE -gt 0 ]] && echo '\033[1;33m--- END OUTPUT ---------------------------\033[0m'
|
||||
export EXIT_CODE=$?
|
||||
[[ $SCWRYPTS_LOG_LEVEL -ge 2 ]] && echo '\033[1;33m--- END OUTPUT ---------------------------\033[0m'
|
||||
|
||||
[[ $EXIT_CODE -eq 0 ]] && EXIT_COLOR='32m' || EXIT_COLOR='31m'
|
||||
[[ $SCWRYPTS_LOG_LEVEL -ge 2 ]] && echo "terminated with\\033[1;$EXIT_COLOR code $EXIT_CODE\\033[0m"
|
||||
|
||||
[[ $VERBOSE -gt 0 ]] && echo "terminated with\\033[1;$EXIT_COLOR code $EXIT_CODE\\033[0m"
|
||||
return $EXIT_CODE
|
||||
} 2>&1 | tee --append "$LOGFILE"
|
||||
|
||||
exit $(\
|
||||
sed -n 's/^terminated with.*code \([0-9]*\).*$/\1/p' $LOGFILE \
|
||||
| tail -n1
|
||||
)
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
@ -343,6 +343,7 @@ __VALIDATE_UPSTREAM_TIMELINE() {
|
||||
|
||||
__GET_LOGFILE() {
|
||||
[ $SUBSCWRYPT ] && return 0
|
||||
[[ $SCWRYPTS_LOG_LEVEL -eq 0 ]] && return 0
|
||||
[[ $SCWRYPT_NAME =~ scwrypts/logs ]] && return 0
|
||||
[[ $SCWRYPT_NAME =~ interactive ]] && return 0
|
||||
|
||||
|
Reference in New Issue
Block a user