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() {
311
311
__bake_internal_die ' Failed to shift'
312
312
fi
313
313
314
- # shellcheck disable=SC1007
315
314
local __bake_key= __bake_value=
316
315
local __bake_arg=
317
316
for __bake_arg; do case $__bake_arg in
Original file line number Diff line number Diff line change 2
2
type = ' bash'
3
3
name = ' bash-core'
4
4
slug = ' core'
5
- version = ' 0.2.0 '
5
+ version = ' 0.3.2 '
6
6
authors = [' Edwin Kofler <edwin@kofler.dev>' ]
7
7
description = ' Core lightweight functions that any Bash programmer will love'
8
8
9
9
[run ]
10
10
dependencies = [' https://github.com/hyperupcall/bats-all.git@v4.1.0' ]
11
- sourceDirs = [' pkg/src/public' ]
11
+ sourceDirs = [' pkg/src/public' , ' pkg/src/util ' ]
12
12
builtinDirs = []
13
13
binDirs = []
14
14
completionDirs = []
Original file line number Diff line number Diff line change @@ -133,12 +133,12 @@ Prints stacktrace
133
133
#### Example
134
134
135
135
``` bash
136
- core.trap_add ' err_handler' EXIT
137
136
err_handler () {
138
137
local exit_code=$?
139
138
core.stacktrace_print
140
- exit $?
139
+ exit $exit_code
141
140
}
141
+ core.trap_add ' err_handler' ERR
142
142
```
143
143
144
144
_ Function has no arguments._
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ core.trap_add() {
44
44
printf ' %s\n' " Error: core.trap_add: Passing numbers for the signal specs is prohibited"
45
45
return 1
46
46
fi ; unset regex
47
- signal_spec=" ${signal_spec# SIG} "
47
+ signal_spec=${signal_spec# SIG}
48
48
if ! declare -f " $function " & > /dev/null; then
49
49
printf ' %s\n' " Error: core.trap_add: Function '$function ' not defined" >&2
50
50
return 1
@@ -55,10 +55,10 @@ core.trap_add() {
55
55
56
56
# rho (WET)
57
57
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} "
59
59
60
60
if ! eval " $global_trap_handler_name () {
61
- core.trap_common_global_handler '$signal_spec '
61
+ core.trap_handler_common '$signal_spec '
62
62
}" ; then
63
63
printf ' %s\n' " Error: core.trap_add: Could not eval function"
64
64
return 1
@@ -253,12 +253,12 @@ core.err_exists() {
253
253
# @description Prints stacktrace
254
254
# @noargs
255
255
# @example
256
- # core.trap_add 'err_handler' EXIT
257
256
# err_handler() {
258
257
# local exit_code=$?
259
258
# core.stacktrace_print
260
- # exit $?
259
+ # exit $exit_code
261
260
# }
261
+ # core.trap_add 'err_handler' ERR
262
262
core.stacktrace_print () {
263
263
printf ' %s\n' ' Stacktrace:'
264
264
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