Skip to content

Commit d633db7

Browse files
authored
Merge pull request asdf-vm#539 from asdf-vm/leonid-shevtsov-install-through-plugins
Leonid shevtsov - install through plugins
2 parents 50c4966 + 3516c08 commit d633db7

2 files changed

Lines changed: 49 additions & 21 deletions

File tree

lib/commands/install.sh

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,35 @@ get_concurrency() {
3737
}
3838

3939
install_local_tool_versions() {
40-
local asdf_versions_path
41-
asdf_versions_path=$(find_tool_versions)
42-
if [ -f "${asdf_versions_path}" ]; then
43-
while IFS= read -r tool_line; do
44-
IFS=' ' read -r -a tool_info <<< "$tool_line"
45-
local tool_name
46-
tool_name=$(echo "${tool_info[0]}" | xargs)
47-
local tool_version
48-
tool_version=$(echo "${tool_info[1]}" | xargs)
49-
50-
if ! [[ -z "$tool_name" || -z "$tool_version" ]]; then
51-
install_tool_version "$tool_name" "$tool_version"
40+
local plugins_path
41+
plugins_path=$(get_plugin_path)
42+
43+
local search_path
44+
search_path=$(pwd)
45+
46+
local some_tools_installed
47+
48+
if ls "$plugins_path" &> /dev/null; then
49+
for plugin_path in "$plugins_path"/* ; do
50+
local plugin_name
51+
plugin_name=$(basename "$plugin_path")
52+
53+
local plugin_version_and_path
54+
plugin_version_and_path="$(find_version "$plugin_name" "$search_path")"
55+
56+
if [ -n "$plugin_version_and_path" ]; then
57+
local plugin_version
58+
some_tools_installed='yes'
59+
plugin_version=$(cut -d '|' -f 1 <<< "$plugin_version_and_path")
60+
install_tool_version "$plugin_name" "$plugin_version"
5261
fi
53-
done <<<"$(strip_tool_version_comments "$asdf_versions_path")"
62+
done
5463
else
64+
echo "Install plugins first to be able to install tools"
65+
exit 1
66+
fi
67+
68+
if [ -z "$some_tools_installed" ]; then
5569
echo "Either specify a tool & version in the command"
5670
echo "OR add .tool-versions file in this directory"
5771
echo "or in a parent directory"

test/install_command.bats

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ teardown() {
2020
[ $(cat $ASDF_DIR/installs/dummy/1.1/version) = "1.1" ]
2121
}
2222

23-
@test "install_command installs even if the user is terrible and does not use newlines" {
23+
@test "install_command without arguments installs even if the user is terrible and does not use newlines" {
2424
cd $PROJECT_DIR
2525
echo -n 'dummy 1.2' > ".tool-versions"
2626
run asdf install
@@ -36,7 +36,7 @@ teardown() {
3636
[ "$status" -eq 0 ]
3737
}
3838

39-
@test "install_command should work in directory containing whitespace" {
39+
@test "install_command without arguments should work in directory containing whitespace" {
4040
WHITESPACE_DIR="$PROJECT_DIR/whitespace\ dir"
4141
mkdir -p "$WHITESPACE_DIR"
4242
cd "$WHITESPACE_DIR"
@@ -78,7 +78,7 @@ teardown() {
7878
[ "$lines_count" -eq "1" ]
7979
}
8080

81-
@test "install_command should not generate shim for subdir" {
81+
@test "install_command without arguments should not generate shim for subdir" {
8282
cd $PROJECT_DIR
8383
echo 'dummy 1.0' > $PROJECT_DIR/.tool-versions
8484

@@ -88,7 +88,7 @@ teardown() {
8888
[ ! -f "$ASDF_DIR/shims/subdir" ]
8989
}
9090

91-
@test "install_command generated shim should pass all arguments to executable" {
91+
@test "install_command without arguments should generate shim that passes all arguments to executable" {
9292
# asdf lib needed to run generated shims
9393
cp -rf $BATS_TEST_DIRNAME/../{bin,lib} $ASDF_DIR/
9494

@@ -114,7 +114,7 @@ teardown() {
114114
[ ! -f $ASDF_DIR/installs/dummy/1.1/version ]
115115
}
116116

117-
@test "install_command uses a parent directory .tool-versions file if present" {
117+
@test "install_command without arguments uses a parent directory .tool-versions file if present" {
118118
# asdf lib needed to run generated shims
119119
cp -rf $BATS_TEST_DIRNAME/../{bin,lib} $ASDF_DIR/
120120

@@ -154,11 +154,25 @@ EOM
154154
[ "$output" == "HEY 1.0 FROM dummy" ]
155155
}
156156

157-
@test "install_command skips comments in .tool-versions file" {
157+
@test "install command without arguments installs versions from legacy files" {
158+
echo 'legacy_version_file = yes' > $HOME/.asdfrc
159+
echo '1.2' >> $PROJECT_DIR/.dummy-version
158160
cd $PROJECT_DIR
159-
echo -n '# dummy 1.2' > ".tool-versions"
160161
run asdf install
161162
[ "$status" -eq 0 ]
162163
[ "$output" == "" ]
163-
[ ! -f $ASDF_DIR/installs/dummy/1.2/version ]
164+
[ -f $ASDF_DIR/installs/dummy/1.2/version ]
165+
}
166+
167+
@test "install command without arguments installs versions from legacy files in parent directories" {
168+
echo 'legacy_version_file = yes' > $HOME/.asdfrc
169+
echo '1.2' >> $PROJECT_DIR/.dummy-version
170+
171+
mkdir -p $PROJECT_DIR/child
172+
cd $PROJECT_DIR/child
173+
174+
run asdf install
175+
[ "$status" -eq 0 ]
176+
[ "$output" == "" ]
177+
[ -f $ASDF_DIR/installs/dummy/1.2/version ]
164178
}

0 commit comments

Comments
 (0)