diff --git a/examples/stacktrace/README.md b/examples/stacktrace/README.md index 63eb53e8..4e54598b 100644 --- a/examples/stacktrace/README.md +++ b/examples/stacktrace/README.md @@ -50,8 +50,7 @@ examples: ## before running anything else. ## ## You can safely delete this file if you do not need it. -trap 'stacktrace' ERR -set -o errtrace +enable_stacktrace ```` @@ -118,8 +117,8 @@ Examples: Stack trace: from ./download:15 in `root_command` - from ./download:254 in `run` - from ./download:260 in `main` + from ./download:260 in `run` + from ./download:266 in `main` ```` diff --git a/examples/stacktrace/src/initialize.sh b/examples/stacktrace/src/initialize.sh index 0fa0e0d6..3fc5c363 100644 --- a/examples/stacktrace/src/initialize.sh +++ b/examples/stacktrace/src/initialize.sh @@ -4,5 +4,4 @@ ## before running anything else. ## ## You can safely delete this file if you do not need it. -trap 'stacktrace' ERR -set -o errtrace +enable_stacktrace diff --git a/examples/stacktrace/src/lib/stacktrace.sh b/examples/stacktrace/src/lib/stacktrace.sh index 570caac3..a93b75dc 100644 --- a/examples/stacktrace/src/lib/stacktrace.sh +++ b/examples/stacktrace/src/lib/stacktrace.sh @@ -4,15 +4,15 @@ ## Usage: ## This function is designed to be called on error. ## -## To enable this functionality, add these lines to your `src/initialize.sh` -## file (Run `bashly add hooks` to add this file): -## -## trap 'stacktrace' ERR -## set -o errtrace -## -## Note that this functionality also requires `set -e`, which is enabled by -## default in bashly generated scripts. +## To enable this functionality, call `enable_stacktrace` in your +## `src/initialize.sh` (Run `bashly add hooks` to add this file). ## +enable_stacktrace() { + trap 'stacktrace' ERR + set -o errtrace + set -o errexit +} + stacktrace() { local exit_status="$?" local i=0 diff --git a/lib/bashly/libraries/libraries.yml b/lib/bashly/libraries/libraries.yml index c25eb1d0..23187b08 100644 --- a/lib/bashly/libraries/libraries.yml +++ b/lib/bashly/libraries/libraries.yml @@ -110,10 +110,10 @@ stacktrace: post_install_message: | The stacktrace function is designed to be called automatically on error. - To enable this functionality, add these lines to your `initialize.sh`: - - g`trap 'stacktrace' ERR` - g`set -o errtrace` + To enable this functionality, call g`enable_stacktrace` in your + g`src/initialize.sh`. You may run the following command to add this file: + + m`$ bashly add hooks` strings: help: Copy an additional configuration file to your project, allowing you to customize all the tips and error strings. diff --git a/lib/bashly/libraries/stacktrace/stacktrace.sh b/lib/bashly/libraries/stacktrace/stacktrace.sh index 570caac3..a93b75dc 100644 --- a/lib/bashly/libraries/stacktrace/stacktrace.sh +++ b/lib/bashly/libraries/stacktrace/stacktrace.sh @@ -4,15 +4,15 @@ ## Usage: ## This function is designed to be called on error. ## -## To enable this functionality, add these lines to your `src/initialize.sh` -## file (Run `bashly add hooks` to add this file): -## -## trap 'stacktrace' ERR -## set -o errtrace -## -## Note that this functionality also requires `set -e`, which is enabled by -## default in bashly generated scripts. +## To enable this functionality, call `enable_stacktrace` in your +## `src/initialize.sh` (Run `bashly add hooks` to add this file). ## +enable_stacktrace() { + trap 'stacktrace' ERR + set -o errtrace + set -o errexit +} + stacktrace() { local exit_status="$?" local i=0 diff --git a/spec/approvals/examples/stacktrace b/spec/approvals/examples/stacktrace index 1f8ecf3d..79a6529d 100644 --- a/spec/approvals/examples/stacktrace +++ b/spec/approvals/examples/stacktrace @@ -3,10 +3,10 @@ created src/lib/stacktrace.sh The stacktrace function is designed to be called automatically on error. -To enable this functionality, add these lines to your `initialize.sh`: +To enable this functionality, call enable_stacktrace in your +src/initialize.sh. You may run the following command to add this file: - trap 'stacktrace' ERR - set -o errtrace + $ bashly add hooks + bashly generate creating user files in src @@ -51,5 +51,5 @@ Examples: Stack trace: from ./download:15 in `root_command` - from ./download:255 in `run` - from ./download:261 in `main` + from ./download:260 in `run` + from ./download:266 in `main`