From d9f65187a1da25256b3c88d650c4d15ac20e4de1 Mon Sep 17 00:00:00 2001 From: Victor Borja Date: Wed, 25 Oct 2017 17:23:48 -0500 Subject: [PATCH] Adding strict mode to all of lib --- bin/asdf | 2 ++ bin/private/asdf-exec | 2 ++ lib/commands/current.sh | 3 +++ lib/commands/help.sh | 3 +++ lib/commands/install.sh | 3 +++ lib/commands/list-all.sh | 3 +++ lib/commands/list.sh | 3 +++ lib/commands/plugin-add.sh | 3 +++ lib/commands/plugin-list-all.sh | 3 +++ lib/commands/plugin-list.sh | 3 +++ lib/commands/plugin-push.sh | 3 +++ lib/commands/plugin-remove.sh | 3 +++ lib/commands/plugin-test.sh | 3 +++ lib/commands/plugin-update.sh | 3 +++ lib/commands/reshim.sh | 3 +++ lib/commands/uninstall.sh | 3 +++ lib/commands/update.sh | 3 +++ lib/commands/version_commands.sh | 3 +++ lib/commands/where.sh | 3 +++ lib/commands/which.sh | 3 +++ lib/utils.sh | 3 +++ release.sh | 7 ++----- 22 files changed, 63 insertions(+), 5 deletions(-) diff --git a/bin/asdf b/bin/asdf index e064320e..fedac8c7 100755 --- a/bin/asdf +++ b/bin/asdf @@ -1,4 +1,6 @@ #!/usr/bin/env bash +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings # shellcheck source=lib/utils.sh source "$(dirname "$(dirname "$0")")/lib/utils.sh" diff --git a/bin/private/asdf-exec b/bin/private/asdf-exec index a6708b69..d476a77f 100755 --- a/bin/private/asdf-exec +++ b/bin/private/asdf-exec @@ -1,4 +1,6 @@ #!/usr/bin/env bash +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings # shellcheck source=lib/utils.sh source "$(dirname "$(dirname "$(dirname "$0")")")/lib/utils.sh" diff --git a/lib/commands/current.sh b/lib/commands/current.sh index 7cf26c95..6cb9acb3 100644 --- a/lib/commands/current.sh +++ b/lib/commands/current.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + plugin_current_command() { local plugin_name=$1 diff --git a/lib/commands/help.sh b/lib/commands/help.sh index d8077e35..73b253b9 100644 --- a/lib/commands/help.sh +++ b/lib/commands/help.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + help_command () { echo "version: $(asdf_version)" echo "" diff --git a/lib/commands/install.sh b/lib/commands/install.sh index a7e5ccd0..df97aff9 100644 --- a/lib/commands/install.sh +++ b/lib/commands/install.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + handle_failure() { local install_path="$1" rm -rf "$install_path" diff --git a/lib/commands/list-all.sh b/lib/commands/list-all.sh index 1c252618..a32d4cca 100644 --- a/lib/commands/list-all.sh +++ b/lib/commands/list-all.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + list_all_command() { local plugin_name=$1 local plugin_path diff --git a/lib/commands/list.sh b/lib/commands/list.sh index 58a51472..0a2f7564 100644 --- a/lib/commands/list.sh +++ b/lib/commands/list.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + list_command() { local plugin_name=$1 check_if_plugin_exists "$plugin_name" diff --git a/lib/commands/plugin-add.sh b/lib/commands/plugin-add.sh index ffb75257..d526a1f7 100644 --- a/lib/commands/plugin-add.sh +++ b/lib/commands/plugin-add.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + plugin_add_command() { if [[ $# -lt 1 || $# -gt 2 ]]; then display_error "usage: asdf plugin-add []" diff --git a/lib/commands/plugin-list-all.sh b/lib/commands/plugin-list-all.sh index 789c2235..26855bbf 100644 --- a/lib/commands/plugin-list-all.sh +++ b/lib/commands/plugin-list-all.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + plugin_list_all_command() { initialize_or_update_repository diff --git a/lib/commands/plugin-list.sh b/lib/commands/plugin-list.sh index 70705b91..fd0c0164 100644 --- a/lib/commands/plugin-list.sh +++ b/lib/commands/plugin-list.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + plugin_list_command() { local plugins_path plugins_path=$(get_plugin_path) diff --git a/lib/commands/plugin-push.sh b/lib/commands/plugin-push.sh index 2cd9b184..a17f52a5 100644 --- a/lib/commands/plugin-push.sh +++ b/lib/commands/plugin-push.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + plugin_push_command() { local plugin_name=$1 if [ "$plugin_name" = "--all" ]; then diff --git a/lib/commands/plugin-remove.sh b/lib/commands/plugin-remove.sh index 14a6c421..7a0384d8 100644 --- a/lib/commands/plugin-remove.sh +++ b/lib/commands/plugin-remove.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + plugin_remove_command() { local plugin_name=$1 check_if_plugin_exists "$plugin_name" diff --git a/lib/commands/plugin-test.sh b/lib/commands/plugin-test.sh index d1ddc0bc..3584bf61 100644 --- a/lib/commands/plugin-test.sh +++ b/lib/commands/plugin-test.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + fail_test() { echo "FAILED: $1" rm -rf "$ASDF_DIR" diff --git a/lib/commands/plugin-update.sh b/lib/commands/plugin-update.sh index 8f2b4c08..011d07ea 100644 --- a/lib/commands/plugin-update.sh +++ b/lib/commands/plugin-update.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + plugin_update_command() { if [ "$#" -ne 1 ]; then display_error "usage: asdf plugin-update { | --all}" diff --git a/lib/commands/reshim.sh b/lib/commands/reshim.sh index b2f08741..1ba40c40 100644 --- a/lib/commands/reshim.sh +++ b/lib/commands/reshim.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + shim_command() { local plugin_name=$1 local executable_path=$2 diff --git a/lib/commands/uninstall.sh b/lib/commands/uninstall.sh index 8a8928e3..db56c130 100644 --- a/lib/commands/uninstall.sh +++ b/lib/commands/uninstall.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + uninstall_command() { local plugin_name=$1 local full_version=$2 diff --git a/lib/commands/update.sh b/lib/commands/update.sh index 1cba8520..4367f400 100644 --- a/lib/commands/update.sh +++ b/lib/commands/update.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + update_command() { local update_to_head=$1 diff --git a/lib/commands/version_commands.sh b/lib/commands/version_commands.sh index d64b4a70..a0a33fb5 100644 --- a/lib/commands/version_commands.sh +++ b/lib/commands/version_commands.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + version_command() { local cmd=$1 local plugin=$2 diff --git a/lib/commands/where.sh b/lib/commands/where.sh index 1286f1d6..72e5b926 100644 --- a/lib/commands/where.sh +++ b/lib/commands/where.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + where_command() { local plugin_name=$1 local full_version=$2 diff --git a/lib/commands/which.sh b/lib/commands/which.sh index 1fa46565..ac9af399 100644 --- a/lib/commands/which.sh +++ b/lib/commands/which.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + current_version() { local plugin_name=$1 diff --git a/lib/utils.sh b/lib/utils.sh index 02a0e03a..b3cd40ae 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -1,3 +1,6 @@ +set -o nounset -o pipefail -o errexit +IFS=$'\t\n' # Stricter IFS settings + # We shouldn't rely on the user's grep settings to be correct. If we set these # here anytime asdf invokes grep it will be invoked with these options # shellcheck disable=SC2034 diff --git a/release.sh b/release.sh index 18996005..65602a29 100755 --- a/release.sh +++ b/release.sh @@ -1,11 +1,8 @@ #!/usr/bin/env bash - -# Unoffical Bash "strict mode" -# http://redsymbol.net/articles/unofficial-bash-strict-mode/ -set -euo pipefail -#ORIGINAL_IFS=$IFS +set -o nounset -o pipefail -o errexit IFS=$'\t\n' # Stricter IFS settings + # shellcheck disable=SC2006 usage() { cat <