mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Merge pull request #237 from DustinChaloupka/install-parent-tool-versions
Add installing from a parent directory's .tool-versions
This commit is contained in:
commit
e2094db465
@ -37,10 +37,9 @@ get_concurrency() {
|
||||
}
|
||||
|
||||
install_local_tool_versions() {
|
||||
if [ -f "$(pwd)/.tool-versions" ]; then
|
||||
local asdf_versions_path
|
||||
asdf_versions_path="$(pwd)/.tool-versions"
|
||||
|
||||
local asdf_versions_path
|
||||
asdf_versions_path=$(find_tool_versions)
|
||||
if [ -f "${asdf_versions_path}" ]; then
|
||||
while read -r tool_line; do
|
||||
IFS=' ' read -r -a tool_info <<< "$tool_line"
|
||||
local tool_name
|
||||
@ -55,6 +54,7 @@ install_local_tool_versions() {
|
||||
else
|
||||
echo "Either specify a tool & version in the command"
|
||||
echo "OR add .tool-versions file in this directory"
|
||||
echo "or in a parent directory"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
12
lib/utils.sh
12
lib/utils.sh
@ -323,3 +323,15 @@ get_plugin_source_url() {
|
||||
grep "repository" "$plugin_config" | awk -F'=' '{print $2}' | sed 's/ //'
|
||||
fi
|
||||
}
|
||||
|
||||
find_tool_versions() {
|
||||
local search_path
|
||||
search_path=$(pwd)
|
||||
while [ "$search_path" != "/" ]; do
|
||||
if [ -f "$search_path/.tool-versions" ]; then
|
||||
echo "${search_path}/.tool-versions"
|
||||
return 0
|
||||
fi
|
||||
search_path=$(dirname "$search_path")
|
||||
done
|
||||
}
|
||||
|
@ -97,3 +97,19 @@ teardown() {
|
||||
[ "$output" = "You must specify a name and a version to install" ]
|
||||
[ ! -f $ASDF_DIR/installs/dummy/1.1/version ]
|
||||
}
|
||||
|
||||
@test "install_command uses a parent directory .tool-versions file if present" {
|
||||
# asdf lib needed to run generated shims
|
||||
cp -rf $BATS_TEST_DIRNAME/../{bin,lib} $ASDF_DIR/
|
||||
|
||||
echo 'dummy 1.0' > $PROJECT_DIR/.tool-versions
|
||||
mkdir -p $PROJECT_DIR/child
|
||||
|
||||
cd $PROJECT_DIR/child
|
||||
|
||||
run install_command
|
||||
|
||||
# execute the generated shim
|
||||
[ "$($ASDF_DIR/shims/dummy world hello)" == "This is Dummy 1.0! hello world" ]
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
@ -207,3 +207,22 @@ teardown() {
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "$executable_path" ]
|
||||
}
|
||||
|
||||
@test "find_tool_versions will find a .tool-versions path if it exists in current directory" {
|
||||
echo "dummy 0.1.0" > $PROJECT_DIR/.tool-versions
|
||||
cd $PROJECT_DIR
|
||||
|
||||
run find_tool_versions
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "$PROJECT_DIR/.tool-versions" ]
|
||||
}
|
||||
|
||||
@test "find_tool_versions will find a .tool-versions path if it exists in parent directory" {
|
||||
echo "dummy 0.1.0" > $PROJECT_DIR/.tool-versions
|
||||
mkdir -p $PROJECT_DIR/child
|
||||
cd $PROJECT_DIR/child
|
||||
|
||||
run find_tool_versions
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "$PROJECT_DIR/.tool-versions" ]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user