Don't allow unset variables in new Bash files

This commit is contained in:
Trevor Brown 2022-05-17 09:30:06 -04:00
parent 1ed64eb119
commit 1c8648dfe3
9 changed files with 47 additions and 46 deletions

View File

@ -2,7 +2,7 @@
set -o nounset set -o nounset
shim_versions_command() { shim_versions_command() {
local shim_name=${1:-} local shim_name="${1:-}"
shim_plugin_versions "$shim_name" shim_plugin_versions "$shim_name"
} }

View File

@ -5,10 +5,10 @@ set -o nounset
. "$(dirname "$ASDF_CMD_FILE")/reshim.bash" . "$(dirname "$ASDF_CMD_FILE")/reshim.bash"
uninstall_command() { uninstall_command() {
local plugin_name=${1:-} local plugin_name="${1:-}"
local full_version=$2 local full_version="${2:-}"
local plugin_path local plugin_path
plugin_path=$(get_plugin_path "$plugin_name") plugin_path="$(get_plugin_path "$plugin_name")"
check_if_plugin_exists "$plugin_name" check_if_plugin_exists "$plugin_name"
@ -22,7 +22,7 @@ uninstall_command() {
fi fi
local install_path local install_path
install_path=$(get_install_path "$plugin_name" "$install_type" "$version") install_path="$(get_install_path "$plugin_name" "$install_type" "$version")"
if [ ! -d "$install_path" ]; then if [ ! -d "$install_path" ]; then
display_error "No such version" display_error "No such version"
@ -47,8 +47,8 @@ uninstall_command() {
} }
remove_shims_for_version() { remove_shims_for_version() {
local plugin_name=${1:-} local plugin_name="${1:-}"
local full_version=$2 local full_version="${2:-}"
for shim_path in $(plugin_shims "$plugin_name" "$full_version"); do for shim_path in $(plugin_shims "$plugin_name" "$full_version"); do
remove_shim_for_version "$plugin_name" "$full_version" "$shim_path" remove_shim_for_version "$plugin_name" "$full_version" "$shim_path"
done done

View File

@ -2,7 +2,7 @@
set -o nounset set -o nounset
update_command() { update_command() {
local update_to_head=${1:-} local update_to_head="${1:-}"
( (
cd "$(asdf_dir)" || exit 1 cd "$(asdf_dir)" || exit 1
@ -17,7 +17,7 @@ update_command() {
} }
do_update() { do_update() {
local update_to_head=${1:-} local update_to_head="${1:-}"
if [ "$update_to_head" = "--head" ]; then if [ "$update_to_head" = "--head" ]; then
# Update to latest on the master branch # Update to latest on the master branch

View File

@ -2,8 +2,8 @@
set -o nounset set -o nounset
where_command() { where_command() {
local plugin_name=${1:-} local plugin_name="${1:-}"
local full_version=${2:-} local full_version="${2:-}"
check_if_plugin_exists "$plugin_name" check_if_plugin_exists "$plugin_name"
local version local version

View File

@ -1,4 +1,5 @@
# -*- sh -*- # -*- sh -*-
set -o nounset set -o nounset
which_command() { which_command() {

View File

@ -27,8 +27,8 @@ remove_shim_for_version() {
} }
reshim_command() { reshim_command() {
local plugin_name=$1 local plugin_name="${1:-}"
local full_version=$2 local full_version="${2:-}"
if [ -z "$plugin_name" ]; then if [ -z "$plugin_name" ]; then
local plugins_path local plugins_path
@ -76,9 +76,9 @@ ensure_shims_dir() {
} }
write_shim_script() { write_shim_script() {
local plugin_name=$1 local plugin_name="${1:-}"
local version=$2 local version="${2:-}"
local executable_path=$3 local executable_path="${3:-}"
if ! is_executable "$executable_path"; then if ! is_executable "$executable_path"; then
return 0 return 0
@ -107,8 +107,8 @@ EOF
} }
generate_shim_for_executable() { generate_shim_for_executable() {
local plugin_name=$1 local plugin_name="${1:-}"
local executable=$2 local executable="${2:-}"
check_if_plugin_exists "$plugin_name" check_if_plugin_exists "$plugin_name"
@ -124,8 +124,8 @@ generate_shim_for_executable() {
} }
generate_shims_for_version() { generate_shims_for_version() {
local plugin_name=$1 local plugin_name="${1:-}"
local full_version=$2 local full_version="${2:-}"
local all_executable_paths local all_executable_paths
IFS=$'\n' read -rd '' -a all_executable_paths <<<"$(plugin_executables "$plugin_name" "$full_version")" IFS=$'\n' read -rd '' -a all_executable_paths <<<"$(plugin_executables "$plugin_name" "$full_version")"
for executable_path in "${all_executable_paths[@]}"; do for executable_path in "${all_executable_paths[@]}"; do
@ -134,8 +134,8 @@ generate_shims_for_version() {
} }
remove_obsolete_shims() { remove_obsolete_shims() {
local plugin_name=$1 local plugin_name="${1:-}"
local full_version=$2 local full_version="${2:-}"
local shims local shims
shims=$(plugin_shims "$plugin_name" "$full_version" | xargs -IX basename X | sort) shims=$(plugin_shims "$plugin_name" "$full_version" | xargs -IX basename X | sort)
@ -148,7 +148,7 @@ remove_obsolete_shims() {
local formatted_exec_names local formatted_exec_names
local temp_dir local temp_dir
temp_dir=${TMPDIR:-/tmp} temp_dir="${TMPDIR:-/tmp}"
# comm only takes to files, so we write this data to temp files so we can # comm only takes to files, so we write this data to temp files so we can
# pass it to comm. # pass it to comm.

View File

@ -1,18 +1,18 @@
handle_failure() { handle_failure() {
local install_path="$1" local install_path="${1:-}"
rm -rf "$install_path" rm -rf "$install_path"
exit 1 exit 1
} }
handle_cancel() { handle_cancel() {
local install_path="$1" local install_path="${1:-}"
printf "\\nreceived sigint, cleaning up" printf "\\nreceived sigint, cleaning up"
handle_failure "$install_path" handle_failure "$install_path"
} }
install_command() { install_command() {
local plugin_name=$1 local plugin_name="${1:-}"
local full_version=$2 local full_version="${2:-}"
local extra_args="${*:3}" local extra_args="${*:3}"
if [ "$plugin_name" = "" ] && [ "$full_version" = "" ]; then if [ "$plugin_name" = "" ] && [ "$full_version" = "" ]; then
@ -37,7 +37,7 @@ get_concurrency() {
} }
install_one_local_tool() { install_one_local_tool() {
local plugin_name=$1 local plugin_name="${1:-}"
local search_path local search_path
search_path=$(pwd) search_path=$(pwd)
@ -131,9 +131,9 @@ install_local_tool_versions() {
} }
install_tool_version() { install_tool_version() {
local plugin_name=$1 local plugin_name="${1:-}"
local full_version=$2 local full_version="${2:-}"
local flags=$3 local flags="${3:-}"
local keep_download local keep_download
local plugin_path local plugin_path

View File

@ -6,7 +6,7 @@ plugin_list_command() {
local show_ref local show_ref
while [ -n "$*" ]; do while [ -n "$*" ]; do
case "$1" in case "${1:-}" in
"--urls") "--urls")
show_repo=true show_repo=true
shift shift
@ -109,8 +109,8 @@ plugin_update_command() {
exit 1 exit 1
fi fi
local plugin_name="$1" local plugin_name="${1:-}"
local gitref="${2}" local gitref="${2:-}"
local plugins= local plugins=
if [ "$plugin_name" = "--all" ]; then if [ "$plugin_name" = "--all" ]; then
@ -130,10 +130,10 @@ plugin_update_command() {
} }
update_plugin() { update_plugin() {
local plugin_name=$1 local plugin_name="${1:-}"
local plugin_path=$2 local plugin_path="${2:-}"
plugin_remote_default_branch=$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" ls-remote --symref origin HEAD | awk '{ sub(/refs\/heads\//, ""); print $2; exit }') plugin_remote_default_branch="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" ls-remote --symref origin HEAD | awk '{ sub(/refs\/heads\//, ""); print $2; exit }')"
local gitref=${3:-${plugin_remote_default_branch}} local gitref="${3:-${plugin_remote_default_branch}}"
logfile=$(mktemp) logfile=$(mktemp)
local common_git_options=(--git-dir "$plugin_path/.git" --work-tree "$plugin_path") local common_git_options=(--git-dir "$plugin_path/.git" --work-tree "$plugin_path")

View File

@ -1,6 +1,6 @@
version_command() { version_command() {
local cmd=$1 local cmd="${1:-}"
local plugin_name=$2 local plugin_name="${2:-}"
if [ "$#" -lt "3" ]; then if [ "$#" -lt "3" ]; then
if [ "$cmd" = "global" ]; then if [ "$cmd" = "global" ]; then
@ -65,17 +65,17 @@ version_command() {
} }
list_all_command() { list_all_command() {
local plugin_name=$1 local plugin_name="${1:-}"
local query=$2 local query="${2:-}"
local plugin_path local plugin_path
local std_out_file local std_out_file
local std_err_file local std_err_file
local output local output
plugin_path=$(get_plugin_path "$plugin_name") plugin_path="$(get_plugin_path "$plugin_name")"
check_if_plugin_exists "$plugin_name" check_if_plugin_exists "$plugin_name"
local temp_dir local temp_dir
temp_dir=${TMPDIR:-/tmp} temp_dir="${TMPDIR:-/tmp}"
# Capture return code to allow error handling # Capture return code to allow error handling
std_out_file="$(mktemp "$temp_dir/asdf-command-list-all-${plugin_name}.stdout.XXXXXX")" std_out_file="$(mktemp "$temp_dir/asdf-command-list-all-${plugin_name}.stdout.XXXXXX")"
@ -117,8 +117,8 @@ list_all_command() {
latest_command() { latest_command() {
DEFAULT_QUERY="[0-9]" DEFAULT_QUERY="[0-9]"
local plugin_name=$1 local plugin_name="${1:-}"
local query=$2 local query="${2:-}"
local plugin_path local plugin_path
if [ "$plugin_name" == "--all" ]; then if [ "$plugin_name" == "--all" ]; then