Don't allow unset variables

This commit is contained in:
Trevor Brown 2020-10-14 16:52:51 -04:00
parent 86537d2a6d
commit 03f2fb7e4c
3 changed files with 12 additions and 9 deletions

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -o nounset
# shellcheck source=lib/utils.bash # shellcheck source=lib/utils.bash
. "$(dirname "$(dirname "$0")")/lib/utils.bash" . "$(dirname "$(dirname "$0")")/lib/utils.bash"

View File

@ -1,11 +1,13 @@
# -*- sh -*- # -*- sh -*-
set -o nounset
# shellcheck source=lib/functions/plugins.bash # shellcheck source=lib/functions/plugins.bash
. "$(dirname "$(dirname "$0")")/lib/functions/plugins.bash" . "$(dirname "$(dirname "$0")")/lib/functions/plugins.bash"
# shellcheck disable=SC2059 # shellcheck disable=SC2059
plugin_current_command() { plugin_current_command() {
local plugin_name=$1 local plugin_name=${1:-}
local terminal_format=$2 local terminal_format=${2:-}
check_if_plugin_exists "$plugin_name" check_if_plugin_exists "$plugin_name"
@ -21,7 +23,7 @@ plugin_current_command() {
local description="" local description=""
IFS=' ' read -r -a versions <<<"$full_version" IFS=' ' read -r -a versions <<<"$full_version"
for version in "${versions[@]}"; do for version in "${versions[@]:-}"; do
if ! (check_if_version_exists "$plugin_name" "$version"); then if ! (check_if_version_exists "$plugin_name" "$version"); then
version_not_installed="$version" version_not_installed="$version"
fi fi

View File

@ -139,7 +139,7 @@ version_not_installed_text() {
} }
get_plugin_path() { get_plugin_path() {
if test -n "$1"; then if test -n "${1:-}"; then
printf "%s\\n" "$(asdf_data_dir)/plugins/$1" printf "%s\\n" "$(asdf_data_dir)/plugins/$1"
else else
printf "%s\\n" "$(asdf_data_dir)/plugins" printf "%s\\n" "$(asdf_data_dir)/plugins"
@ -212,7 +212,7 @@ find_versions() {
get_version_in_dir "$plugin_name" "$HOME" "$legacy_filenames" get_version_in_dir "$plugin_name" "$HOME" "$legacy_filenames"
if [ -f "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" ]; then if [ -f "${ASDF_DEFAULT_TOOL_VERSIONS_FILENAME:-}" ]; then
versions=$(parse_asdf_version_file "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" "$plugin_name") versions=$(parse_asdf_version_file "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" "$plugin_name")
if [ -n "$versions" ]; then if [ -n "$versions" ]; then
printf "%s\\n" "$versions|$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" printf "%s\\n" "$versions|$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME"
@ -244,21 +244,21 @@ find_install_path() {
if [ "$version" = "system" ]; then if [ "$version" = "system" ]; then
printf "\\n" printf "\\n"
elif [ "${version_info[0]}" = "ref" ]; then elif [ "${version_info[0]:-}" = "ref" ]; then
local install_type="${version_info[0]}" local install_type="${version_info[0]}"
local version="${version_info[1]}" local version="${version_info[1]}"
get_install_path "$plugin_name" "$install_type" "$version" get_install_path "$plugin_name" "$install_type" "$version"
elif [ "${version_info[0]}" = "path" ]; then elif [ "${version_info[0]:-}" = "path" ]; then
# This is for people who have the local source already compiled # This is for people who have the local source already compiled
# Like those who work on the language, etc # Like those who work on the language, etc
# We'll allow specifying path:/foo/bar/project in .tool-versions # We'll allow specifying path:/foo/bar/project in .tool-versions
# And then use the binaries there # And then use the binaries there
local install_type="path" local install_type="path"
local version="path" local version="path"
printf "%s\\n" "${version_info[1]}" printf "%s\\n" "${version_info[1]:-}"
else else
local install_type="version" local install_type="version"
local version="${version_info[0]}" local version="${version_info[0]:-}"
get_install_path "$plugin_name" "$install_type" "$version" get_install_path "$plugin_name" "$install_type" "$version"
fi fi
} }