mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Return both version and path from find_version
This allows the current command to print the setting file.
This commit is contained in:
parent
cec4e9a737
commit
d505c0ee71
@ -2,10 +2,13 @@ current_command() {
|
||||
local plugin_name=$1
|
||||
|
||||
check_if_plugin_exists $plugin_name
|
||||
local version_file_path=$(find_version_file_for $plugin_name)
|
||||
local version=$(parse_version_file $version_file_path $plugin_name)
|
||||
check_if_version_exists $plugin_name $version
|
||||
|
||||
local search_path=$(pwd)
|
||||
local version_and_path=$(find_version "$plugin_name" "$search_path")
|
||||
local version=$(cut -d ':' -f 1 <<< "$version_and_path");
|
||||
local version_file_path=$(cut -d ':' -f 2 <<< "$version_and_path");
|
||||
|
||||
check_if_version_exists $plugin_name $version
|
||||
check_for_deprecated_plugin $plugin_name
|
||||
|
||||
if [ -z "$version" ]; then
|
||||
|
11
lib/utils.sh
11
lib/utils.sh
@ -56,7 +56,7 @@ display_error() {
|
||||
echo >&2 $1
|
||||
}
|
||||
|
||||
find_version_for() {
|
||||
find_version() {
|
||||
local plugin_name=$1
|
||||
local search_path=$2
|
||||
|
||||
@ -73,7 +73,7 @@ find_version_for() {
|
||||
local asdf_version=$(parse_asdf_version_file "$search_path/.tool-versions" $plugin_name)
|
||||
|
||||
if [ -n "$asdf_version" ]; then
|
||||
echo "$asdf_version"
|
||||
echo "$asdf_version:$search_path/.tool-versions"
|
||||
return 0
|
||||
fi
|
||||
|
||||
@ -81,7 +81,7 @@ find_version_for() {
|
||||
local legacy_version=$(parse_legacy_version_file "$search_path/$filename" $plugin_name)
|
||||
|
||||
if [ -n "$legacy_version" ]; then
|
||||
echo "$legacy_version"
|
||||
echo "$legacy_version:$search_path/$filename"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
@ -124,8 +124,11 @@ parse_legacy_version_file() {
|
||||
|
||||
get_preset_version_for() {
|
||||
local plugin_name=$1
|
||||
local search_path=$(pwd)
|
||||
local version_and_path=$(find_version "$plugin_name" "$search_path")
|
||||
local version=$(cut -d ':' -f 1 <<< "$version_and_path");
|
||||
|
||||
echo "$(find_version "$plugin_name" "$search_path")"
|
||||
echo "$version"
|
||||
}
|
||||
|
||||
get_asdf_config_value_from_file() {
|
||||
|
@ -52,7 +52,7 @@ teardown() {
|
||||
|
||||
run find_version "dummy" $PROJECT_DIR
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "0.1.0" ]
|
||||
[ "$output" = "0.1.0:$PROJECT_DIR/.tool-versions" ]
|
||||
}
|
||||
|
||||
@test "find_version should return the legacy file if supported" {
|
||||
@ -62,7 +62,7 @@ teardown() {
|
||||
|
||||
run find_version "dummy" $PROJECT_DIR
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "0.2.0" ]
|
||||
[ "$output" = "0.2.0:$PROJECT_DIR/.dummy-version" ]
|
||||
}
|
||||
|
||||
@test "find_version skips .tool-version file that don't list the plugin" {
|
||||
@ -71,7 +71,7 @@ teardown() {
|
||||
|
||||
run find_version "dummy" $PROJECT_DIR
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "0.1.0" ]
|
||||
[ "$output" = "0.1.0:$HOME/.tool-versions" ]
|
||||
}
|
||||
|
||||
@test "find_version should return .tool-versions if unsupported" {
|
||||
@ -82,7 +82,7 @@ teardown() {
|
||||
|
||||
run find_version "dummy" $PROJECT_DIR
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "0.1.0" ]
|
||||
[ "$output" = "0.1.0:$HOME/.tool-versions" ]
|
||||
}
|
||||
|
||||
@test "get_preset_version_for returns the current version" {
|
||||
|
Loading…
Reference in New Issue
Block a user