mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Rename find_version to find_versions since it can return multiple versions
This commit is contained in:
parent
cea9b9574f
commit
edb5839239
@ -6,7 +6,7 @@ plugin_current_command() {
|
||||
local search_path
|
||||
search_path=$(pwd)
|
||||
local version_and_path
|
||||
version_and_path=$(find_version "$plugin_name" "$search_path")
|
||||
version_and_path=$(find_versions "$plugin_name" "$search_path")
|
||||
local full_version
|
||||
full_version=$(cut -d '|' -f 1 <<< "$version_and_path");
|
||||
local version_file_path
|
||||
|
@ -51,7 +51,7 @@ install_local_tool_versions() {
|
||||
plugin_name=$(basename "$plugin_path")
|
||||
|
||||
local plugin_version_and_path
|
||||
plugin_version_and_path="$(find_version "$plugin_name" "$search_path")"
|
||||
plugin_version_and_path="$(find_versions "$plugin_name" "$search_path")"
|
||||
|
||||
if [ -n "$plugin_version_and_path" ]; then
|
||||
local plugin_version
|
||||
|
@ -7,7 +7,7 @@ where_command() {
|
||||
local install_type="version"
|
||||
if [[ -z ${full_version} ]]; then
|
||||
local version_and_path
|
||||
version_and_path=$(find_version "$plugin_name" "$PWD")
|
||||
version_and_path=$(find_versions "$plugin_name" "$PWD")
|
||||
version=$(cut -d '|' -f 1 <<< "$version_and_path");
|
||||
else
|
||||
local -a version_info
|
||||
|
12
lib/utils.sh
12
lib/utils.sh
@ -133,7 +133,7 @@ get_version_in_dir() {
|
||||
done
|
||||
}
|
||||
|
||||
find_version() {
|
||||
find_versions() {
|
||||
local plugin_name=$1
|
||||
local search_path=$2
|
||||
|
||||
@ -172,9 +172,9 @@ find_version() {
|
||||
get_version_in_dir "$plugin_name" "$HOME" "$legacy_filenames"
|
||||
|
||||
if [ -f "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" ]; then
|
||||
version=$(parse_asdf_version_file "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" "$plugin_name")
|
||||
if [ -n "$version" ]; then
|
||||
echo "$version|$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME"
|
||||
versions=$(parse_asdf_version_file "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" "$plugin_name")
|
||||
if [ -n "$versions" ]; then
|
||||
echo "$versions|$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
@ -300,7 +300,7 @@ get_preset_version_for() {
|
||||
local search_path
|
||||
search_path=$(pwd)
|
||||
local version_and_path
|
||||
version_and_path=$(find_version "$plugin_name" "$search_path")
|
||||
version_and_path=$(find_versions "$plugin_name" "$search_path")
|
||||
local version
|
||||
version=$(cut -d '|' -f 1 <<< "$version_and_path");
|
||||
|
||||
@ -635,7 +635,7 @@ with_shim_executable() {
|
||||
local version_string
|
||||
local usable_plugin_versions
|
||||
local _path
|
||||
version_and_path=$(find_version "$plugin_name" "$search_path")
|
||||
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
|
||||
|
@ -85,49 +85,49 @@ teardown() {
|
||||
[ "$output" == "path:/some/dummy path" ]
|
||||
}
|
||||
|
||||
@test "find_version should return .tool-versions if legacy is disabled" {
|
||||
@test "find_versions should return .tool-versions if legacy is disabled" {
|
||||
echo "dummy 0.1.0" > $PROJECT_DIR/.tool-versions
|
||||
echo "0.2.0" > $PROJECT_DIR/.dummy-version
|
||||
|
||||
run find_version "dummy" $PROJECT_DIR
|
||||
run find_versions "dummy" $PROJECT_DIR
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "0.1.0|$PROJECT_DIR/.tool-versions" ]
|
||||
}
|
||||
|
||||
@test "find_version should return the legacy file if supported" {
|
||||
@test "find_versions should return the legacy file if supported" {
|
||||
echo "legacy_version_file = yes" > $HOME/.asdfrc
|
||||
echo "dummy 0.1.0" > $HOME/.tool-versions
|
||||
echo "0.2.0" > $PROJECT_DIR/.dummy-version
|
||||
|
||||
run find_version "dummy" $PROJECT_DIR
|
||||
run find_versions "dummy" $PROJECT_DIR
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "0.2.0|$PROJECT_DIR/.dummy-version" ]
|
||||
}
|
||||
|
||||
@test "find_version skips .tool-version file that don't list the plugin" {
|
||||
@test "find_versions skips .tool-version file that don't list the plugin" {
|
||||
echo "dummy 0.1.0" > $HOME/.tool-versions
|
||||
echo "another_plugin 0.3.0" > $PROJECT_DIR/.tool-versions
|
||||
|
||||
run find_version "dummy" $PROJECT_DIR
|
||||
run find_versions "dummy" $PROJECT_DIR
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "0.1.0|$HOME/.tool-versions" ]
|
||||
}
|
||||
|
||||
@test "find_version should return .tool-versions if unsupported" {
|
||||
@test "find_versions should return .tool-versions if unsupported" {
|
||||
echo "dummy 0.1.0" > $HOME/.tool-versions
|
||||
echo "0.2.0" > $PROJECT_DIR/.dummy-version
|
||||
echo "legacy_version_file = yes" > $HOME/.asdfrc
|
||||
rm $ASDF_DIR/plugins/dummy/bin/list-legacy-filenames
|
||||
|
||||
run find_version "dummy" $PROJECT_DIR
|
||||
run find_versions "dummy" $PROJECT_DIR
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "0.1.0|$HOME/.tool-versions" ]
|
||||
}
|
||||
|
||||
@test "find_version should return the version set by envrionment variable" {
|
||||
@test "find_versions should return the version set by envrionment variable" {
|
||||
export ASDF_DUMMY_VERSION=0.2.0
|
||||
|
||||
run find_version "dummy" $PROJECT_DIR
|
||||
run find_versions "dummy" $PROJECT_DIR
|
||||
[ "$status" -eq 0 ]
|
||||
echo $output
|
||||
[ "$output" = "0.2.0|ASDF_DUMMY_VERSION environment variable" ]
|
||||
@ -155,22 +155,22 @@ teardown() {
|
||||
[ "$output" = "" ]
|
||||
}
|
||||
|
||||
@test "find_version should return \$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME if set" {
|
||||
@test "find_versions should return \$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME if set" {
|
||||
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions"
|
||||
echo "dummy 0.1.0" > $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME
|
||||
|
||||
run find_version "dummy" $PROJECT_DIR
|
||||
run find_versions "dummy" $PROJECT_DIR
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "0.1.0|$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" ]
|
||||
}
|
||||
|
||||
@test "find_version should check \$HOME legacy files before \$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" {
|
||||
@test "find_versions should check \$HOME legacy files before \$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" {
|
||||
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions"
|
||||
echo "dummy 0.2.0" > $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME
|
||||
echo "dummy 0.1.0" > $HOME/.dummy-version
|
||||
echo "legacy_version_file = yes" > $HOME/.asdfrc
|
||||
|
||||
run find_version "dummy" $PROJECT_DIR
|
||||
run find_versions "dummy" $PROJECT_DIR
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "0.1.0|$HOME/.dummy-version" ]]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user