diff --git a/bin/asdf b/bin/asdf index 439fd1814..25279c5b1 100755 --- a/bin/asdf +++ b/bin/asdf @@ -7,6 +7,8 @@ fi # shellcheck source=lib/utils.bash . "$(dirname "$(dirname "$0")")/lib/utils.bash" +# shellcheck source=lib/functions/versions.bash +. "$(dirname "$(dirname "$0")")/lib/functions/versions.bash" find_cmd() { local cmd_dir="$1" diff --git a/lib/functions/versions.bash b/lib/functions/versions.bash index 7d1d941d6..b796408a5 100644 --- a/lib/functions/versions.bash +++ b/lib/functions/versions.bash @@ -37,27 +37,7 @@ version_command() { declare -a resolved_versions local item for item in "${!versions[@]}"; do - IFS=':' read -r -a version_info <<<"${versions[$item]}" - if [ "${version_info[0]}" = "latest" ] && [ -n "${version_info[1]}" ]; then - version=$(latest_command "$plugin_name" "${version_info[1]}") - elif [ "${version_info[0]}" = "latest" ] && [ -z "${version_info[1]}" ]; then - version=$(latest_command "$plugin_name") - else - # if branch handles ref: || path: || normal versions - version="${versions[$item]}" - fi - - # check_if_version_exists should probably handle if either param is empty string - if [ -z "$version" ]; then - exit 1 - fi - - if ! (check_if_version_exists "$plugin_name" "$version"); then - version_not_installed_text "$plugin_name" "$version" 1>&2 - exit 1 - fi - - resolved_versions+=("$version") + resolved_versions+=("$(resolve_version_spec "${versions[$item]}")") done if [ -f "$file" ] && grep -q "^$plugin_name " "$file"; then @@ -79,6 +59,32 @@ version_command() { fi } +resolve_version_spec() { + local version_spec=$1 + + IFS=':' read -r -a version_info <<<"$version_spec" + if [ "${version_info[0]}" = "latest" ] && [ -n "${version_info[1]}" ]; then + version=$(latest_command "$plugin_name" "${version_info[1]}") + elif [ "${version_info[0]}" = "latest" ] && [ -z "${version_info[1]}" ]; then + version=$(latest_command "$plugin_name") + else + # if branch handles ref: || path: || normal versions + version="${versions[$item]}" + fi + + # check_if_version_exists should probably handle if either param is empty string + if [ -z "$version" ]; then + exit 1 + fi + + if ! (check_if_version_exists "$plugin_name" "$version"); then + version_not_installed_text "$plugin_name" "$version" 1>&2 + exit 1 + fi + + printf "%s\n" "$version" +} + list_all_command() { local plugin_name=$1 local query=$2 diff --git a/lib/utils.bash b/lib/utils.bash index 21978a929..8b40bf548 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -736,7 +736,8 @@ select_version() { version_and_path=$(find_versions "$plugin_name" "$search_path") IFS='|' read -r version_string _path <<<"$version_and_path" IFS=' ' read -r -a usable_plugin_versions <<<"$version_string" - for plugin_version in "${usable_plugin_versions[@]}"; do + for version_spec in "${usable_plugin_versions[@]}"; do + plugin_version="$(resolve_version_spec "$version_spec")" for plugin_and_version in "${shim_versions[@]}"; do local plugin_shim_name local plugin_shim_version