mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Add support for $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME
Instead of just looking in $HOME/.tool-versions, allow the default tool-versions file location to be specified through the variable $ASDF_TOOL_VERSIONS.
This commit is contained in:
parent
663ebb9a2f
commit
15e59686c4
@ -12,7 +12,7 @@ version_command() {
|
||||
|
||||
local file
|
||||
if [ $cmd = "global" ]; then
|
||||
file=$HOME/.tool-versions
|
||||
file=${ASDF_DEFAULT_TOOL_VERSIONS_FILENAME:-$HOME/.tool-versions}
|
||||
else
|
||||
file=$(pwd)/.tool-versions
|
||||
fi
|
||||
|
@ -137,6 +137,14 @@ find_version() {
|
||||
done
|
||||
|
||||
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"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
get_version_from_env () {
|
||||
|
@ -124,6 +124,26 @@ teardown() {
|
||||
[ "$output" = "0.1.0|$HOME/.tool-versions" ]
|
||||
}
|
||||
|
||||
@test "find_version 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
|
||||
[ "$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" {
|
||||
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
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "0.1.0|$HOME/.dummy-version" ]
|
||||
}
|
||||
|
||||
@test "get_preset_version_for returns the current version" {
|
||||
cd $PROJECT_DIR
|
||||
echo "dummy 0.2.0" > .tool-versions
|
||||
|
@ -114,3 +114,20 @@ teardown() {
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(cat $HOME/.tool-versions)" = "dummy path:$PROJECT_DIR/local" ]
|
||||
}
|
||||
|
||||
@test "global should write to ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" {
|
||||
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions"
|
||||
run global_command "dummy" "1.1.0"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(cat $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME)" = "dummy 1.1.0" ]
|
||||
[ "$(cat $HOME/.tool-versions)" = "" ]
|
||||
}
|
||||
|
||||
@test "global should overwrite contents of ASDF_DEFAULT_TOOL_VERSIONS_FILENAME if set" {
|
||||
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions"
|
||||
echo 'dummy 1.0.0' >> "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME"
|
||||
run global_command "dummy" "1.1.0"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(cat $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME)" = "dummy 1.1.0" ]
|
||||
[ "$(cat $HOME/.tool-versions)" = "" ]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user