From 9430a39aef1dbf806a8954d71711747be1001076 Mon Sep 17 00:00:00 2001 From: Alberto de Murga Date: Fri, 1 Oct 2021 14:38:57 +0200 Subject: [PATCH] feat: Displays a warning when a plugin from the tools-version list does 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 https://github.com/asdf-vm/asdf/issues/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. --- lib/commands/command-install.bash | 37 ++++++++++++++++++++++++++++--- test/install_command.bats | 18 +++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/lib/commands/command-install.bash b/lib/commands/command-install.bash index a8c769f0a..20ed3910a 100644 --- a/lib/commands/command-install.bash +++ b/lib/commands/command-install.bash @@ -62,6 +62,7 @@ install_one_local_tool() { exit 1 fi } + install_local_tool_versions() { local plugins_path plugins_path=$(get_plugin_path) @@ -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")" @@ -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 diff --git a/test/install_command.bats b/test/install_command.bats index 127a23ecc..0d990c5e3 100644 --- a/test/install_command.bats +++ b/test/install_command.bats @@ -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