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:
Hugo Peixoto 2017-09-14 12:21:36 +01:00
parent 663ebb9a2f
commit 15e59686c4
4 changed files with 46 additions and 1 deletions

View File

@ -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

View File

@ -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 () {

View File

@ -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

View File

@ -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)" = "" ]
}