Refactored run function

This commit is contained in:
Андрей Лимачко 2022-12-06 16:48:09 +04:00
parent 7ea1b20042
commit 410b2d8821
Signed by untrusted user: liannnix
GPG Key ID: 1D8EEB2E408272C0

View File

@ -153,12 +153,23 @@ __delimiter()
echo "-------------------------------------------------------------------------------" echo "-------------------------------------------------------------------------------"
} }
__check_title()
{
color_message "$1" bold white
}
__newline() __newline()
{ {
echo echo
} }
__log() __log()
{
test -z $verbose && tee -a "$logfile" 2>&1 >/dev/null ||
tee -a "$logfile"
}
__log_force_print()
{ {
tee -a "$logfile" tee -a "$logfile"
} }
@ -169,28 +180,19 @@ run()
local func="$1" local func="$1"
local msg=$(printf "| %s |" "$func") local msg=$(printf "| %s |" "$func")
# Verbose disabled, logging enabled
test -z $verbose && __header | __log 2>&1 >/dev/null ||
__header | __log __header | __log
if test -z $verbose; then __check_title "$msg" | __log
$func 2>&1 | __log >/dev/null 2>&1 && retval=0 || retval=$? __delimiter | __log
else
color_message "$msg" bold white | __log
test -z $verbose || __delimiter | __log
__newline | __log __newline | __log
$func 2>&1 | __log && retval=0 || retval=$?
fi
test -z $verbose && __delimiter | __log 2>&1 >/dev/null || $func 2>&1 | __log && retval=0 || retval=$?
__delimiter | __log __delimiter | __log
__short_msg $retval "$2" | __log __short_msg $retval "$2" | __log_force_print
test -z $verbose && __footer | __log 2>&1 >/dev/null ||
__footer | __log __footer | __log
test -z $verbose && __newline | __log 2>&1 >/dev/null ||
__newline | __log __newline | __log
} }