Изменил(а) на 'shell/helpers.sh'

This commit is contained in:
Anthony Axenov 2023-07-10 10:47:25 +00:00
parent 566424b15b
commit e384d15d4b

View File

@ -224,8 +224,8 @@ dt() {
echo "[$(date +'%H:%M:%S')] " echo "[$(date +'%H:%M:%S')] "
} }
ask() { ask() {
IFS= read -rp "$(print ${BOLD}${BBLUE}${FWHITE}${IASK}${BRESET}\ ${BOLD}$1 ): " $2 IFS= read -rp "$(print ${BOLD}${BBLUE}${FWHITE}${IASK}${BRESET}\ ${BOLD}$1 ): " $2
} }
print() { print() {
@ -234,48 +234,48 @@ print() {
debug() { debug() {
if [ "$2" ]; then if [ "$2" ]; then
print "${DIM}${BOLD}${RESET}${DIM} ${FUNCNAME[1]:-?}():${BASH_LINENO:-?}\t$1 " print "${DIM}${BOLD}${RESET}${DIM}$(dt)${IDEBUG} ${FUNCNAME[1]:-?}():${BASH_LINENO:-?}\t$1 " >&2
else else
print "${DIM}${BOLD}${RESET}${DIM}$1 " print "${DIM}${BOLD}${RESET}${DIM}$(dt)${IDEBUG} $1 " >&2
fi fi
} }
var_dump() { var_dump() {
debug "$1 = ${!1}" 0 debug "$1 = ${!1}"
} }
verbose() { verbose() {
print "${BOLD}${IVRB}${RESET}${FYELLOW} $1 " print "${BOLD}$(dt)${IVRB}${RESET}${FYELLOW} $1 "
} }
info() { info() {
print "${BOLD}${FWHITE}${BLBLUE}${IINFO}${RESET}${FWHITE} $1 " print "${BOLD}$(dt)${FWHITE}${BLBLUE}${IINFO}${RESET}${FWHITE} $1 "
} }
note() { note() {
print "${BOLD}${DIM}${FWHITE}${INOTE}${RESET} $1 " print "${BOLD}$(dt)${DIM}${FWHITE}${INOTE}${RESET} $1 "
} }
success() { success() {
print "${BOLD}${BGREEN}${FWHITE}${ISUCCESS}${BRESET}$FGREEN $1 " print "${BOLD}$(dt)${BGREEN}${FWHITE}${ISUCCESS}${BRESET}$FGREEN $1 "
} }
warn() { warn() {
print "${BOLD}${BYELLOW}${FBLACK}${IWARN}${BRESET}${FYELLOW} Warning:${RESET} $1 " print "${BOLD}$(dt)${BYELLOW}${FBLACK}${IWARN}${BRESET}${FYELLOW} Warning:${RESET} $1 "
} }
error() { error() {
print "${BOLD}${BLRED}${FWHITE}${IERROR} Error: ${BRESET}${FLRED} $1 " >&2 print "${BOLD}$(dt)${BLRED}${FWHITE}${IERROR} Error: ${BRESET}${FLRED} $1 " >&2
} }
fatal() { fatal() {
print "${BOLD}${BRED}${FWHITE}${IFATAL} FATAL: $1 " >&2 print "${BOLD}$(dt)${BRED}${FWHITE}${IFATAL} FATAL: $1 " >&2
print_stacktrace print_stacktrace
} }
die() { die() {
error "${1:-halted}" error "${1:-halted}"
exit ${2:-100} exit ${2:-255}
} }
print_stacktrace() { print_stacktrace() {
@ -294,6 +294,18 @@ print_stacktrace() {
done done
} }
# var='test var_dump'
# var_dump var
# debug 'test debug'
# verbose 'test verbose'
# info 'test info'
# note 'test note'
# success 'test success'
# warn 'test warn'
# error 'test error'
# fatal 'test fatal'
# die 'test die'
######################################################## ########################################################
# Tests # Tests
######################################################## ########################################################
@ -609,4 +621,4 @@ git.require_clean_worktree() {
# https://gitlab.com/kyb/autorsync/-/blob/master/ # https://gitlab.com/kyb/autorsync/-/blob/master/
# https://lug.fh-swf.de/vim/vim-bash/StyleGuideShell.en.pdf # https://lug.fh-swf.de/vim/vim-bash/StyleGuideShell.en.pdf
# https://www.thegeekstuff.com/2010/06/bash-array-tutorial/ # https://www.thegeekstuff.com/2010/06/bash-array-tutorial/
# https://www.distributednetworks.com/linux-network-admin/module4/ephemeral-reserved-portNumbers.php # https://www.distributednetworks.com/linux-network-admin/module4/ephemeral-reserved-portNumbers.php