File tree Expand file tree Collapse file tree 5 files changed +30
-10
lines changed Expand file tree Collapse file tree 5 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -311,7 +311,6 @@ __bake_main() {
311311 __bake_internal_die ' Failed to shift'
312312 fi
313313
314- # shellcheck disable=SC1007
315314 local __bake_key= __bake_value=
316315 local __bake_arg=
317316 for __bake_arg; do case $__bake_arg in
Original file line number Diff line number Diff line change 22type = ' bash'
33name = ' bash-core'
44slug = ' core'
5- version = ' 0.2.0 '
5+ version = ' 0.3.2 '
66authors = [' Edwin Kofler <edwin@kofler.dev>' ]
77description = ' Core lightweight functions that any Bash programmer will love'
88
99[run ]
1010dependencies = [' https://github.com/hyperupcall/bats-all.git@v4.1.0' ]
11- sourceDirs = [' pkg/src/public' ]
11+ sourceDirs = [' pkg/src/public' , ' pkg/src/util ' ]
1212builtinDirs = []
1313binDirs = []
1414completionDirs = []
Original file line number Diff line number Diff line change @@ -133,12 +133,12 @@ Prints stacktrace
133133#### Example
134134
135135``` bash
136- core.trap_add ' err_handler' EXIT
137136err_handler () {
138137 local exit_code=$?
139138 core.stacktrace_print
140- exit $?
139+ exit $exit_code
141140}
141+ core.trap_add ' err_handler' ERR
142142```
143143
144144_ Function has no arguments._
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ core.trap_add() {
4444 printf ' %s\n' " Error: core.trap_add: Passing numbers for the signal specs is prohibited"
4545 return 1
4646 fi ; unset regex
47- signal_spec=" ${signal_spec# SIG} "
47+ signal_spec=${signal_spec# SIG}
4848 if ! declare -f " $function " & > /dev/null; then
4949 printf ' %s\n' " Error: core.trap_add: Function '$function ' not defined" >&2
5050 return 1
@@ -55,10 +55,10 @@ core.trap_add() {
5555
5656 # rho (WET)
5757 local global_trap_handler_name=
58- printf -v global_trap_handler_name ' %q' " ___global_trap_ ${signal_spec} _handler___ "
58+ printf -v global_trap_handler_name ' %q' " core.trap_handler_ ${signal_spec} "
5959
6060 if ! eval " $global_trap_handler_name () {
61- core.trap_common_global_handler '$signal_spec '
61+ core.trap_handler_common '$signal_spec '
6262}" ; then
6363 printf ' %s\n' " Error: core.trap_add: Could not eval function"
6464 return 1
@@ -253,12 +253,12 @@ core.err_exists() {
253253# @description Prints stacktrace
254254# @noargs
255255# @example
256- # core.trap_add 'err_handler' EXIT
257256# err_handler() {
258257# local exit_code=$?
259258# core.stacktrace_print
260- # exit $?
259+ # exit $exit_code
261260# }
261+ # core.trap_add 'err_handler' ERR
262262core.stacktrace_print () {
263263 printf ' %s\n' ' Stacktrace:'
264264
Original file line number Diff line number Diff line change 1+ # shellcheck shell=bash
2+
3+ core.trap_handler_common () {
4+ local signal_spec=" $1 "
5+
6+ local trap_handlers=
7+ IFS=$' \x1C ' read -ra trap_handlers <<< " ${___global_trap_table___[$signal_spec]}"
8+
9+ local trap_handler=
10+ for trap_handler in " ${trap_handlers[@]} " ; do
11+ if [ -z " $trap_handler " ]; then
12+ continue
13+ fi
14+
15+ if declare -f " $trap_handler " & > /dev/null; then
16+ " $trap_handler "
17+ else
18+ printf " %s\n" " Warn: core.trap_add: Function '$trap_handler ' registered for signal '$signal_spec ' no longer exists. Skipping" >&2
19+ fi
20+ done ; unset trap_func
21+ }
You can’t perform that action at this time.
0 commit comments