Skip to content

Commit 2f8ffab

Browse files
committed
Fix asdf-vm#15: asdf install from .tool-versions; Fix loops
1 parent d428c04 commit 2f8ffab

2 files changed

Lines changed: 53 additions & 24 deletions

File tree

lib/commands/install.sh

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
11
install_command() {
22
local plugin_name=$1
33
local full_version=$2
4+
5+
if [ "$plugin_name" = "" ] && [ "$full_version" = "" ]; then
6+
install_local_tool_versions
7+
else
8+
install_tool_version $plugin_name $full_version
9+
fi
10+
}
11+
12+
13+
install_local_tool_versions() {
14+
if [ -f $(pwd)/.tool-versions ]; then
15+
local asdf_versions_path=$(pwd)/.tool-versions
16+
echo "Reading $asdf_versions_path" >> ~/.asdf.log
17+
18+
local read_done=false
19+
until $read_done; do
20+
read tool_line || read_done=true
21+
IFS=' ' read -a tool_info <<< $tool_line
22+
local t_name=$(echo "${tool_info[0]}" | xargs)
23+
local t_version=$(echo "${tool_info[1]}" | xargs)
24+
25+
install_command $t_name $t_version
26+
done < $asdf_versions_path
27+
else
28+
echo "Either specify a tool & version in the command"
29+
echo "OR add .tool-versions file in this directory"
30+
exit 1
31+
fi
32+
}
33+
34+
35+
install_tool_version() {
36+
local plugin_name=$1
37+
local full_version=$2
438
local plugin_path=$(get_plugin_path $plugin_name)
539
check_if_plugin_exists $plugin_path
640

41+
742
IFS=':' read -a version_info <<< "$full_version"
843
if [ "${version_info[0]}" = "ref" ]; then
944
local install_type="${version_info[0]}"
@@ -13,24 +48,24 @@ install_command() {
1348
local version="${version_info[0]}"
1449
fi
1550

51+
1652
local install_path=$(get_install_path $plugin_name $install_type $version)
1753
if [ -d $install_path ]; then
1854
echo "$plugin_name $full_version is already installed"
19-
echo "To uninstall it run: asdf uninstall $plugin_name $full_version"
20-
exit 0
21-
fi
22-
23-
(
24-
export ASDF_INSTALL_TYPE=$install_type
25-
export ASDF_INSTALL_VERSION=$version
26-
export ASDF_INSTALL_PATH=$install_path
27-
mkdir $install_path
28-
bash ${plugin_path}/bin/install
29-
)
30-
local exit_code=$?
31-
if [ $exit_code -eq 0 ]; then
32-
reshim_command $plugin_name $full_version
3355
else
34-
exit $exit_code
56+
(
57+
export ASDF_INSTALL_TYPE=$install_type
58+
export ASDF_INSTALL_VERSION=$version
59+
export ASDF_INSTALL_PATH=$install_path
60+
mkdir $install_path
61+
bash ${plugin_path}/bin/install
62+
)
63+
64+
local exit_code=$?
65+
if [ $exit_code -eq 0 ]; then
66+
reshim_command $plugin_name $full_version
67+
else
68+
exit $exit_code
69+
fi
3570
fi
3671
}

lib/utils.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ get_asdf_versions_file_path() {
6565
search_path=$(dirname $search_path)
6666
done
6767

68-
69-
if [ "$asdf_tool_versions_path" = "" ]; then
70-
asdf_tool_versions_path=$HOME/.tool-versions
71-
if [ ! -f $asdf_tool_versions_path ]; then
72-
touch $asdf_tool_versions_path
73-
fi
74-
fi
7568
echo $asdf_tool_versions_path
7669
}
7770

@@ -107,8 +100,9 @@ get_tool_version_from_file() {
107100
local tool_name=$2
108101
local matching_tool_version=""
109102

110-
while read tool_line
111-
do
103+
local read_done=false
104+
until $read_done; do
105+
read tool_line || read_done=true
112106
IFS=' ' read -a tool_info <<< $tool_line
113107
local t_name=$(echo "${tool_info[0]}" | xargs)
114108
local t_version=$(echo "${tool_info[1]}" | xargs)

0 commit comments

Comments
 (0)