Merge pull request #539 from asdf-vm/leonid-shevtsov-install-through-plugins

Leonid shevtsov - install through plugins
This commit is contained in:
Trevor Brown 2019-06-17 20:59:22 -04:00 committed by GitHub
commit d633db78bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 20 deletions

View File

@ -37,21 +37,35 @@ get_concurrency() {
}
install_local_tool_versions() {
local asdf_versions_path
asdf_versions_path=$(find_tool_versions)
if [ -f "${asdf_versions_path}" ]; then
while IFS= read -r tool_line; do
IFS=' ' read -r -a tool_info <<< "$tool_line"
local tool_name
tool_name=$(echo "${tool_info[0]}" | xargs)
local tool_version
tool_version=$(echo "${tool_info[1]}" | xargs)
local plugins_path
plugins_path=$(get_plugin_path)
if ! [[ -z "$tool_name" || -z "$tool_version" ]]; then
install_tool_version "$tool_name" "$tool_version"
local search_path
search_path=$(pwd)
local some_tools_installed
if ls "$plugins_path" &> /dev/null; then
for plugin_path in "$plugins_path"/* ; do
local plugin_name
plugin_name=$(basename "$plugin_path")
local plugin_version_and_path
plugin_version_and_path="$(find_version "$plugin_name" "$search_path")"
if [ -n "$plugin_version_and_path" ]; then
local plugin_version
some_tools_installed='yes'
plugin_version=$(cut -d '|' -f 1 <<< "$plugin_version_and_path")
install_tool_version "$plugin_name" "$plugin_version"
fi
done <<<"$(strip_tool_version_comments "$asdf_versions_path")"
done
else
echo "Install plugins first to be able to install tools"
exit 1
fi
if [ -z "$some_tools_installed" ]; then
echo "Either specify a tool & version in the command"
echo "OR add .tool-versions file in this directory"
echo "or in a parent directory"

View File

@ -20,7 +20,7 @@ teardown() {
[ $(cat $ASDF_DIR/installs/dummy/1.1/version) = "1.1" ]
}
@test "install_command installs even if the user is terrible and does not use newlines" {
@test "install_command without arguments installs even if the user is terrible and does not use newlines" {
cd $PROJECT_DIR
echo -n 'dummy 1.2' > ".tool-versions"
run asdf install
@ -36,7 +36,7 @@ teardown() {
[ "$status" -eq 0 ]
}
@test "install_command should work in directory containing whitespace" {
@test "install_command without arguments should work in directory containing whitespace" {
WHITESPACE_DIR="$PROJECT_DIR/whitespace\ dir"
mkdir -p "$WHITESPACE_DIR"
cd "$WHITESPACE_DIR"
@ -78,7 +78,7 @@ teardown() {
[ "$lines_count" -eq "1" ]
}
@test "install_command should not generate shim for subdir" {
@test "install_command without arguments should not generate shim for subdir" {
cd $PROJECT_DIR
echo 'dummy 1.0' > $PROJECT_DIR/.tool-versions
@ -88,7 +88,7 @@ teardown() {
[ ! -f "$ASDF_DIR/shims/subdir" ]
}
@test "install_command generated shim should pass all arguments to executable" {
@test "install_command without arguments should generate shim that passes all arguments to executable" {
# asdf lib needed to run generated shims
cp -rf $BATS_TEST_DIRNAME/../{bin,lib} $ASDF_DIR/
@ -114,7 +114,7 @@ teardown() {
[ ! -f $ASDF_DIR/installs/dummy/1.1/version ]
}
@test "install_command uses a parent directory .tool-versions file if present" {
@test "install_command without arguments 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/
@ -154,11 +154,25 @@ EOM
[ "$output" == "HEY 1.0 FROM dummy" ]
}
@test "install_command skips comments in .tool-versions file" {
@test "install command without arguments installs versions from legacy files" {
echo 'legacy_version_file = yes' > $HOME/.asdfrc
echo '1.2' >> $PROJECT_DIR/.dummy-version
cd $PROJECT_DIR
echo -n '# dummy 1.2' > ".tool-versions"
run asdf install
[ "$status" -eq 0 ]
[ "$output" == "" ]
[ ! -f $ASDF_DIR/installs/dummy/1.2/version ]
[ -f $ASDF_DIR/installs/dummy/1.2/version ]
}
@test "install command without arguments installs versions from legacy files in parent directories" {
echo 'legacy_version_file = yes' > $HOME/.asdfrc
echo '1.2' >> $PROJECT_DIR/.dummy-version
mkdir -p $PROJECT_DIR/child
cd $PROJECT_DIR/child
run asdf install
[ "$status" -eq 0 ]
[ "$output" == "" ]
[ -f $ASDF_DIR/installs/dummy/1.2/version ]
}