fix: Allow path: versions to use ~ (#1403)

This commit is contained in:
Edwin Kofler 2023-01-06 04:08:48 -08:00 committed by GitHub
parent 4125d2b556
commit 670c96d1a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 6 deletions

View File

@ -31,7 +31,7 @@ The versions can be in the following format:
- `10.15.0` - an actual version. Plugins that support downloading binaries, will download binaries.
- `ref:v1.0.2-a` or `ref:39cb398vb39` - tag/commit/branch to download from github and compile
- `path:/src/elixir` - a path to custom compiled version of a tool to use. For use by language developers and such.
- `path:~/src/elixir` - a path to custom compiled version of a tool to use. For use by language developers and such.
- `system` - this keyword causes asdf to passthrough to the version of the tool on the system that is not managed by asdf.
::: tip

View File

@ -22,7 +22,7 @@ As versões podem estar no seguinte formato:
- `10.15.0` - uma versão real. Os plugins que suportam o download de binários farão o download de binários.
- `ref:v1.0.2-a` ou `ref:39cb398vb39` - _tag/commit/branch_ para download pelo github e compilação
um path costumizado e compi
- `path:/src/elixir` - um path para uma versão compilada e personalizada de uma ferramenta pronta para usar. Para uso por linguagens de desenvolvimento e outros.
- `path:~/src/elixir` - um path para uma versão compilada e personalizada de uma ferramenta pronta para usar. Para uso por linguagens de desenvolvimento e outros.
- `system` - faz com que asdf passe para a versão da ferramenta no sistema que não é gerenciada por asdf .
Várias versões podem ser definidas, separando-as com um espaço. Por exemplo, para usar Python 3.7.2, e também Python 2.7.15, use a linha abaixo em seu arquivo `.tool-versions`.

View File

@ -29,7 +29,7 @@ nodejs 10.15.0
- `10.15.0` - 实际的版本号。支持下载二进制文件的插件将会下载二进制文件。
- `ref:v1.0.2-a` 或者 `ref:39cb398vb39` - 指定标签/提交/分支从 github 下载并编译。
- `path:/src/elixir` - 要使用的工具的自定义编译版本的路径。这种方式供语言开发者等使用。
- `path:~/src/elixir` - 要使用的工具的自定义编译版本的路径。这种方式供语言开发者等使用。
- `system` - 此关键字会导致 asdf 传递系统上未由 asdf 管理的工具版本。
::: tip 提示

View File

@ -64,7 +64,7 @@ version_command() {
sed -i.bak -e "s|^$plugin_name .*$|$plugin_name ${resolved_versions[*]}|" "$file"
rm -f "$file".bak
else
# Add a trailing newline at the end of the file if missing and file present
# Add a trailing newline at the end of the file if missing
[[ -f "$file" && -n "$(tail -c1 "$file")" ]] && printf '\n' >>"$file"
# Add a new version line to the end of the file

View File

@ -263,7 +263,9 @@ find_install_path() {
# And then use the binaries there
local install_type="path"
local version="path"
printf "%s\n" "${version_info[1]}"
util_resolve_user_path "${version_info[1]}"
printf "%s\n" "${util_resolve_user_path_reply}"
else
local install_type="version"
local version="${version_info[0]}"
@ -319,8 +321,15 @@ parse_asdf_version_file() {
if [ -f "$file_path" ]; then
local version
version=$(strip_tool_version_comments "$file_path" | grep "^${plugin_name} " | sed -e "s/^${plugin_name} //")
if [ -n "$version" ]; then
if [[ "$version" == path:* ]]; then
util_resolve_user_path "${version#path:}"
printf "%s\n" "path:${util_resolve_user_path_reply}"
else
printf "%s\n" "$version"
fi
return 0
fi
fi
@ -837,3 +846,17 @@ remove_path_from_path() {
local path=$2
substitute "$PATH" "$path" "" | sed -e "s|::|:|g"
}
# @description Strings that began with a ~ are always paths. In
# that case, then ensure ~ it handled like a shell
util_resolve_user_path() {
util_resolve_user_path_reply=
local path="$1"
# shellcheck disable=SC2088
if [ "${path::2}" = '~/' ]; then
util_resolve_user_path_reply="${HOME}/${path:2}"
else
util_resolve_user_path_reply="$path"
fi
}

View File

@ -133,6 +133,13 @@ teardown() {
[ "$output" == "path:/some/dummy path" ]
}
@test "parse_asdf_version_file should output path version with tilda" {
echo "dummy path:~/some/dummy path" >$PROJECT_DIR/.tool-versions
run parse_asdf_version_file $PROJECT_DIR/.tool-versions dummy
[ "$status" -eq 0 ]
[ "$output" == "path:$HOME/some/dummy path" ]
}
@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
@ -272,6 +279,14 @@ teardown() {
[ "$output" = "path:/some/place with spaces" ]
}
@test "get_preset_version_for should return path version with tilda" {
cd $PROJECT_DIR
echo "dummy path:~/some/place with spaces" >$PROJECT_DIR/.tool-versions
run get_preset_version_for "dummy"
[ "$status" -eq 0 ]
[ "$output" = "path:$HOME/some/place with spaces" ]
}
@test "get_executable_path for system version should return system path" {
mkdir -p $ASDF_DIR/plugins/foo
run get_executable_path "foo" "system" "ls"