Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Displays a warning when a plugin from the tools-version list does not exist #1033

Merged
merged 7 commits into from Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 34 additions & 3 deletions lib/commands/command-install.bash
Expand Up @@ -62,6 +62,7 @@ install_one_local_tool() {
exit 1
fi
}

install_local_tool_versions() {
local plugins_path
plugins_path=$(get_plugin_path)
Expand All @@ -70,12 +71,45 @@ install_local_tool_versions() {
search_path=$(pwd)

local some_tools_installed
local some_plugin_not_installed

local tool_versions_path
tool_versions_path=$(find_tool_versions)

# Locate all the plugins installed in the system
local plugins_installed
if ls "$plugins_path" &>/dev/null; then
for plugin_path in "$plugins_path"/*; do
local plugin_name
plugin_name=$(basename "$plugin_path")
plugins_installed="$plugins_installed $plugin_name"
done
plugins_installed=$(printf "%s" "$plugins_installed" | tr " " "\n")
fi

if [ -z "$plugins_installed" ]; then
printf "Install plugins first to be able to install tools\\n"
exit 1
fi

# Locate all the plugins defined in the versions file.
local tools_file
if [ -f "$tool_versions_path" ]; then
tools_file=$(strip_tool_version_comments "$tool_versions_path" | cut -d ' ' -f 1)
for plugin_name in $tools_file; do
if ! printf '%s\n' "${plugins_installed[@]}" | grep -q "^$plugin_name\$"; then
printf "%s plugin is not installed\n" "$plugin_name"
some_plugin_not_installed='yes'
fi
done
fi

if [ -n "$some_plugin_not_installed" ]; then
exit 1
fi

if [ -n "$plugins_installed" ]; then
for plugin_name in $plugins_installed; do
local plugin_version_and_path
plugin_version_and_path="$(find_versions "$plugin_name" "$search_path")"

Expand All @@ -88,9 +122,6 @@ install_local_tool_versions() {
done
fi
done
else
printf "Install plugins first to be able to install tools\\n"
exit 1
fi

if [ -z "$some_tools_installed" ]; then
Expand Down
18 changes: 18 additions & 0 deletions test/install_command.bats
Expand Up @@ -133,6 +133,24 @@ teardown() {
[ ! -f $ASDF_DIR/installs/dummy/1.1.0/version ]
}

@test "install_command fails if the plugin is not installed" {
cd $PROJECT_DIR
echo 'other_dummy 1.0.0' > $PROJECT_DIR/.tool-versions

run asdf install
[ "$status" -eq 1 ]
[ "$output" = "other_dummy plugin is not installed" ]
}

@test "install_command fails if the plugin is not installed without collisions" {
cd $PROJECT_DIR
printf "dummy 1.0.0\ndum 1.0.0" > $PROJECT_DIR/.tool-versions

run asdf install
[ "$status" -eq 1 ]
[ "$output" = "dum plugin is not installed" ]
}

@test "install_command fails when tool is specified but no version of the tool is configured in config file" {
echo 'dummy 1.0.0' > $PROJECT_DIR/.tool-versions
run asdf install other-dummy
Expand Down