Revision 9235
Added by Aaron Marcuse-Kubitza over 11 years ago
util.sh | ||
---|---|---|
74 | 74 |
|
75 | 75 |
#### functions |
76 | 76 |
|
77 |
params() # usage: func() { params param_var...; }; ...; param_var=... cmd
|
|
77 |
kw_params() # usage: func() { kw_params param_var...; }; ...; param_var=... cmd
|
|
78 | 78 |
# removes keyword-param-only vars from the environment |
79 | 79 |
{ unexport "$@"; } |
80 | 80 |
|
... | ... | |
227 | 227 |
log_e() { log_err "command exited with error $e"; } |
228 | 228 |
|
229 | 229 |
# usage: cmd || [type=...] die msg |
230 |
die() { save_e; params type; "log_${type:-err}" "$1"; rethrow; } |
|
230 |
die() { save_e; kw_params type; "log_${type:-err}" "$1"; rethrow; }
|
|
231 | 231 |
|
232 | 232 |
|
233 | 233 |
#### functions |
... | ... | |
282 | 282 |
function command() # usage: [cmd_log_fd=|1|2|#] command extern_cmd... |
283 | 283 |
# to view only explicitly-displayed errors: explicit_errors_only=1 script... |
284 | 284 |
{ |
285 |
params cmd_log_fd |
|
285 |
kw_params cmd_log_fd
|
|
286 | 286 |
|
287 | 287 |
cmd2rel_path; (echo_params; can_log) && indent || true |
288 | 288 |
( |
... | ... | |
308 | 308 |
function echo_func() # usage: [minor=1] "echo_func" "$@" && indent || true |
309 | 309 |
# exit status: whether function call was echoed |
310 | 310 |
{ |
311 |
params minor |
|
311 |
kw_params minor
|
|
312 | 312 |
|
313 | 313 |
log++; if test "$minor"; then log++; fi |
314 | 314 |
local script="$(canon_rel_path "${BASH_SOURCE[1]}")" |
... | ... | |
336 | 336 |
alias export="echo_export" # automatically echo env vars when they are set |
337 | 337 |
fi |
338 | 338 |
|
339 |
func_override params__lang |
|
340 |
params() { params__lang "$@"; echo_vars "$@"; } # echo all keyword params
|
|
339 |
func_override kw_params__lang
|
|
340 |
kw_params() { kw_params__lang "$@"; echo_vars "$@"; } # echo all keyword params
|
|
341 | 341 |
|
342 | 342 |
|
343 | 343 |
### external command input/output |
... | ... | |
375 | 375 |
|
376 | 376 |
set_fd() # usage: dest=fd dir='[<>]' src=fd [noclobber=1] set_fd |
377 | 377 |
{ |
378 |
echo_func; params dest dir src |
|
378 |
echo_func; kw_params dest dir src
|
|
379 | 379 |
: "${dest:?}" "${dir:?}" "${src:?}" |
380 | 380 |
test ! "$noclobber" || require_fd_not_exists "$dest" || return 0 |
381 | 381 |
echo_eval exec "$dest$dir&$src" |
... | ... | |
423 | 423 |
# auto-removes a command's output file on error (like make's .DELETE_ON_ERROR) |
424 | 424 |
function to_file() # usage: stdout=... [if_not_exists=1] to_file cmd... |
425 | 425 |
{ |
426 |
echo_func; params stdout |
|
426 |
echo_func; kw_params stdout
|
|
427 | 427 |
: "${stdout?}" |
428 | 428 |
test ! "$if_not_exists" || require_not_exists "$stdout" || return 0 |
429 | 429 |
"$@" >"$stdout" || { save_e; log_e; rm "$stdout"; rethrow; } |
Also available in: Unified diff
lib/sh/util.sh: renamed params() to kw_params() to clarify the type of params it handles