mbland / go-script-bash

Framework for writing modular, discoverable, testable Bash scripts
ISC License
95 stars 16 forks source link

[WIP] Adds partial support for the unofficial bash strict mode #230

Closed nkakouros closed 5 years ago

nkakouros commented 6 years ago

cc: @mbland

I run my scripts with set -euo pipefail at the very top. I run into some unbound variables when doing so. Maybe I'll run into more as I move into using this framework. I think it is good to have default values/explicit null to make assumptions in the code clearer.

On the part where I changed := to :-, I did so to avoid running the same value assignment twice.

This PR is regardless of #220, but it could prove handy if #220 starts getting implemented. This PR is meant to support those users that do want the strict mode in their scripts.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-21.8%) to 73.216% when pulling 2f126ca98acd8cb739d855bd428e991e693c1788 on tterranigma:unbound into b8d71406075bed5eea9ea575ec9547c7a4505d1a on mbland:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-21.9%) to 73.14% when pulling cca38a866e85d2e78bd589b80824320200859bb3 on tterranigma:unbound into b8d71406075bed5eea9ea575ec9547c7a4505d1a on mbland:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-22.7%) to 72.306% when pulling c1423d75f814ade0453043440153eb571f118186 on tterranigma:unbound into b8d71406075bed5eea9ea575ec9547c7a4505d1a on mbland:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-22.7%) to 72.306% when pulling 6bbf0c986bd16aa807eb3a4f0da307fbc282814d on tterranigma:unbound into b8d71406075bed5eea9ea575ec9547c7a4505d1a on mbland:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-21.9%) to 73.152% when pulling 82015412440c59e2ed6aec5a206f161c06056b2b on tterranigma:unbound into b8d71406075bed5eea9ea575ec9547c7a4505d1a on mbland:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-22.4%) to 72.673% when pulling 7e92dd54779238f2a52c70117c0b63b93f550ccb on tterranigma:unbound into b8d71406075bed5eea9ea575ec9547c7a4505d1a on mbland:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-22.4%) to 72.663% when pulling d8f6d9ecc1f091fcba71e3b9c6f43495dc5a688d on tterranigma:unbound into b8d71406075bed5eea9ea575ec9547c7a4505d1a on mbland:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-22.4%) to 72.663% when pulling d8f6d9ecc1f091fcba71e3b9c6f43495dc5a688d on tterranigma:unbound into b8d71406075bed5eea9ea575ec9547c7a4505d1a on mbland:master.

nkakouros commented 6 years ago

I have a question. When using bash autocomplete, there are around 4,5 commands that return '1' if no candidate for completion is found. When setting set -e, this stops execution at the first such command. This is no problem, as the completion would anyway return nothing in the command line. But when using trap custom_function ERR without set -e, the commands that return 1 cause custom_function to run as many times as there are such commands. This is bad as the user receives unexpected output when instead nothing should be printed in the command line pressing TAB. Should this PR try to 'fix' these commands as well? In my own projects, I take care of the situation in my custom_function by searching for libexec/complete in "${BASH_SOURCE[@]}" and doingset -- ERR` if found.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-22.4%) to 72.675% when pulling 9f38958c52478eb144123c4d45bd6a219ac18030 on tterranigma:unbound into b8d71406075bed5eea9ea575ec9547c7a4505d1a on mbland:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-22.4%) to 72.675% when pulling 0899bfe9c504977b5761130e84c8dbff9fc7559e on tterranigma:unbound into b8d71406075bed5eea9ea575ec9547c7a4505d1a on mbland:master.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-22.3%) to 72.725% when pulling 91dc1c28c98692eba28010cdad3b3dd8669706fb on tterranigma:unbound into b8d71406075bed5eea9ea575ec9547c7a4505d1a on mbland:master.