mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Improve which command to work with arbitrary shims
This commit is contained in:
parent
a44ec2779a
commit
bb7f5d031f
@ -4,10 +4,11 @@ current_version() {
|
||||
check_if_plugin_exists "$plugin_name"
|
||||
|
||||
local search_path
|
||||
search_path=$(pwd)
|
||||
local version_and_path
|
||||
version_and_path=$(find_version "$plugin_name" "$search_path")
|
||||
local version
|
||||
|
||||
search_path=$(pwd)
|
||||
version_and_path=$(find_version "$plugin_name" "$search_path")
|
||||
version=$(cut -d '|' -f 1 <<< "$version_and_path");
|
||||
|
||||
check_if_version_exists "$plugin_name" "$version"
|
||||
@ -23,31 +24,62 @@ current_version() {
|
||||
}
|
||||
|
||||
which_command() {
|
||||
local plugin_name=$1
|
||||
local plugin_path
|
||||
plugin_path=$(get_plugin_path "$plugin_name")
|
||||
check_if_plugin_exists "$plugin_name"
|
||||
local install_type="version"
|
||||
local bin_name=$1
|
||||
local shim_path
|
||||
local plugin_name
|
||||
local plugin_versions_and_paths
|
||||
local plugin_versions
|
||||
|
||||
local install_path
|
||||
install_path=$(get_install_path "$plugin_name" "$install_type" "$(current_version "$plugin_name")")
|
||||
shim_path="$(asdf_dir)/shims/$bin_name"
|
||||
|
||||
if [ -d "$install_path" ]; then
|
||||
echo "$install_path/bin/$plugin_name"
|
||||
exit 0
|
||||
else
|
||||
echo "Version not installed"
|
||||
if [ ! -f "$shim_path" ]; then
|
||||
echo "no shim found for $bin_name"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
plugin_name="$(sed -ne 's/# asdf-plugin: \(.*\)/\1/p' "$shim_path")"
|
||||
|
||||
if [ -z "$plugin_name" ]; then
|
||||
if soft_check_if_plugin_exists "$bin_name"; then
|
||||
plugin_name="$bin_name"
|
||||
else
|
||||
echo "could not determine plugin for $bin_name"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
check_if_plugin_exists "$plugin_name"
|
||||
|
||||
|
||||
plugin_versions_and_paths=$(find_version "$plugin_name" "$(pwd)")
|
||||
IFS=' ' read -ra plugin_versions <<< "$(cut -d '|' -f 1 <<< "$plugin_versions_and_paths")"
|
||||
|
||||
binary_versions=($(sed -ne 's/# asdf-plugin-version: \(.*\)/\1/p' "$shim_path"))
|
||||
|
||||
if [ "${#binary_versions[@]}" -eq 0 ]; then
|
||||
binary_versions=($plugin_versions)
|
||||
fi
|
||||
|
||||
for plugin_version in "${plugin_versions[@]}"; do
|
||||
for binary_version in "${binary_versions[@]}"; do
|
||||
if [ "$plugin_version" = "$binary_version" ]; then
|
||||
echo "$(asdf_dir)/installs/$plugin_name/$plugin_version/bin/$bin_name"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
echo "could not find installed version for $bin_name"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Warn if the plugin isn't using the updated legacy file api.
|
||||
check_for_deprecated_plugin() {
|
||||
local plugin_name=$1
|
||||
|
||||
local plugin_path
|
||||
plugin_path=$(get_plugin_path "$plugin_name")
|
||||
local legacy_config
|
||||
|
||||
plugin_path=$(get_plugin_path "$plugin_name")
|
||||
legacy_config=$(get_asdf_config_value "legacy_version_file")
|
||||
local deprecated_script="${plugin_path}/bin/get-version-from-legacy-file"
|
||||
local new_script="${plugin_path}/bin/list-legacy-filenames"
|
||||
|
10
lib/utils.sh
10
lib/utils.sh
@ -53,15 +53,21 @@ list_installed_versions() {
|
||||
fi
|
||||
}
|
||||
|
||||
check_if_plugin_exists() {
|
||||
soft_check_if_plugin_exists() {
|
||||
# Check if we have a non-empty argument
|
||||
if [ -z "${1}" ]; then
|
||||
display_error "No plugin given"
|
||||
exit 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$(asdf_dir)/plugins/$1" ]; then
|
||||
display_error "No such plugin"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_if_plugin_exists() {
|
||||
if ! soft_check_if_plugin_exists "$1"; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user