Skip to content

Commit

Permalink
feat: Displays a warning when a plugin from the tools-version list do…
Browse files Browse the repository at this point in the history
…es not exist (#1033)

* feat: Displays a warning when the plugin from the tools-version does not exist

When calling the install command, it tried to look for versions for all
the plugins available and installed them. With this change, it will attempt to
find versions for all the installed plugins and plugins defined in the
`.tool-versions`.

Fixes #574

* feat: Changes the algorithm to detect not installed plugins

This patch changes the algorithm. It preserves the original logic for
the plugin resolution, but at the same time, reports entries with plugins not
available.

* fix: Addresses the pull request comments.

- Changes the comparison to be strict rather than partial.
- Prints a list of missing plugins.
- Exists if at least one plugin is not present.
- Adds unit tests.
  • Loading branch information
threkk committed Oct 1, 2021
1 parent 43412aa commit 9430a39
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
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

0 comments on commit 9430a39

Please sign in to comment.