midipix / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

Blame subr/ex_rtl_log.subr

Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
#
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
# set -o errexit -o noglob are assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
#
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_log_env_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	local _nvar=1 _arg _arg_len_max=0;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	ex_log_msg info "Variables for this ${1:-build}:"; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	while [ ${_nvar} -le ${#} ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		_arg="$(eval echo \${${_nvar}})";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		_arg="${_arg%%=*}";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		if [ ${#_arg} -gt ${_arg_len_max} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			_arg_len_max=${#_arg};
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		fi; : $((_nvar+=1));
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		ex_log_msg info "$(printf					\
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			"%${_arg_len_max}.${_arg_len_max}s=%s"	\
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
			"${1%%=*}" "$(ex_get_var_unsafe ${1#*=})")";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
};
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
ex_log_msg() {
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	local _lvl="${1}"; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 648b81
	if [ "${_lvl}" = vnfo ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	&& [ ${ARG_VERBOSE:-0} -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		return;
Lucio Andrés Illanes Albornoz (arab, vxp) 648b81
	elif [ "${_lvl}" = vvfo ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 3961f3
	&& [ ${ARG_VERBOSE2:-0} -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 648b81
		return;
Lucio Andrés Illanes Albornoz (arab, vxp) 648b81
	elif [ "${_lvl}" = vvvo ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 3961f3
	&& [ ${ARG_VERBOSE3:-0} -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 648b81
		return;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	case "${_lvl}" in
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		failexit) printf "\033[0m\033[${LOG_MSG_FAIL_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		fail) printf "\033[0m\033[${LOG_MSG_FAIL_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		info) printf "\033[0m\033[${LOG_MSG_INFO_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 3961f3
		vnfo) printf "\033[0m\033[${LOG_MSG_VNFO_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 3961f3
		vvfo) printf "\033[0m\033[${LOG_MSG_VVFO_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 3961f3
		vvvo) printf "\033[0m\033[${LOG_MSG_VVVO_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		succ) printf "\033[0m\033[${LOG_MSG_SUCC_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	esac;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	if [ ${#} -gt 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		printf "==> %s %s %s\033[0m\n" "$(ex_date)" "${1}" "$*";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	else
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		printf "==> %s %s\033[0m\n" "$(ex_date)" "${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
	fi; [ ${_lvl} = failexit ] && exit 1 || return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
};
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
# vim:filetype=sh