=== modified file 'bin/confz' --- bin/confz 2014-06-19 16:32:25 +0000 +++ bin/confz 2014-06-19 14:56:15 +0000 @@ -5,41 +5,12 @@ 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 - ${(p)confz_err_mark} "$@" >&2 + print -r - "$@" >&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() { @@ -62,7 +33,7 @@ done } -# check & run & check a dependency +# check & run a dependency require() { # usage: require [] [-- ] # where: @@ -75,7 +46,7 @@ # to variable ${vars[bar]} of caller # are arguments passed to the dependency function - local name outer inner indent_prev check_only_prev + local name outer inner local -a do_command_prev local -A vars_switch lift @@ -104,23 +75,10 @@ do_command=( confz_${name}_do ) # perform check & run - 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 + if confz_${name}_check "$@"; then + "${do_command[@]}" "$@" || die "$name: command failed with error $?" 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[@]}" )