confz

git mirror of https://ccx.te2000.cz/bzr/confz
git clone https://ccx.te2000.cz/git/confz
Log | Files | Refs

commit c7033116234f5cd573b6d872525673bd6b4872b9
parent 7d992bf7d09e0f1de2a897ec6b32534e3a594018
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Thu, 19 Jun 2014 18:32:25 +0200

print command execution trace
Diffstat:
Mbin/confz | 52+++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/bin/confz b/bin/confz @@ -5,12 +5,41 @@ setopt extended_glob warn_create_global typeset -gA vars vars_prev typeset -ga do_command +typeset -g confz_indent check_only + +check_only=0 # helper that prints out error message and exits die() { - print -r - "$@" >&2 + print -r - ${(p)confz_err_mark} "$@" >&2 exit 1 } +confz_err_mark="%F[red]*%f" + +# trace-printing helpers +confz_exe_mark="%F[yellow]*%f" + +confz_check_start() { + print -Pn "${indent}checking %B$1%b " + print -rn - ${(@q)argv[2,-1]} + print -P " [" + confz_indent+=" " +} + +confz_check_ok() { + confz_indent=${confz_indent% } + print -P "$indent] %F[green]$1%f OK" +} + +confz_check_fail() { + confz_indent=${confz_indent% } + print -P "$indent] %F[yellow]$1%f FAIL" +} + +confz_do() { + print -r - $indent${(p)confz_exe_mark} "${(q)@}" + "$@" || die "command failed with error $?: ${(q)@}" +} # autoload all relevant functions and run confz_*_init confz_load() { @@ -33,7 +62,7 @@ confz_load() { done } -# check & run a dependency +# check & run & check a dependency require() { # usage: require <name> [<variables>] [-- <arguments>] # where: @@ -46,7 +75,7 @@ require() { # to variable ${vars[bar]} of caller # <arguments> are arguments passed to the dependency function - local name outer inner + local name outer inner indent_prev check_only_prev local -a do_command_prev local -A vars_switch lift @@ -75,10 +104,23 @@ require() { do_command=( confz_${name}_do ) # perform check & run - if confz_${name}_check "$@"; then - "${do_command[@]}" "$@" || die "$name: command failed with error $?" + if ! (($check_only)); then + confz_check_start $name "$@" + if confz_${name}_check "$@"; then + confz_check_ok $name + else + confz_check_fail + confz_do "${do_command[@]}" "$@" + fi fi + + # perform check once again + check_only_prev=$check_only + check_only=1 + confz_check_start $name "$@" confz_${name}_check "$@" || die "$name: check failed with error $?" + confz_check_ok $name + check_only=$check_only_prev # restore $do_command do_command=( "${do_command_prev[@]}" )