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

fix: shim and preset plugin mismatch message #1724

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ with_shim_executable() {
(
local preset_plugin_versions
preset_plugin_versions=()
local preset_plugin_installed=
local closest_tool_version
closest_tool_version=$(find_tool_versions)

Expand All @@ -815,22 +816,32 @@ with_shim_executable() {
IFS=' ' read -r -a shim_versions <<<"$version_string"
local usable_plugin_versions
for shim_version in "${shim_versions[@]}"; do
preset_plugin_versions+=("$shim_plugin $shim_version")
if grep -q "$shim_version" <<<"$(asdf list "$shim_plugin")"; then
preset_plugin_installed="yes"
else
preset_plugin_versions+=("$shim_plugin $shim_version")
fi
done
done

if [ -n "${preset_plugin_versions[*]}" ]; then
printf "%s %s\n" "No preset version installed for command" "$shim_name"
printf "%s\n\n" "Please install a version by running one of the following:"
for preset_plugin_version in "${preset_plugin_versions[@]}"; do
printf "%s %s\n" "asdf install" "$preset_plugin_version"
done
printf "\n%s %s\n" "or add one of the following versions in your config file at" "$closest_tool_version"
if [ -n "$preset_plugin_installed" ]; then
printf "%s '%s' %s\n" "Shimmed command" "$shim_name" "has no matched plugin version"
printf "%s %s %s\n" "Check the executable or try install" "$shim_name" "for your preset plugin version"
else
printf "%s %s\n" "No version is set for command" "$shim_name"
printf "%s %s\n" "Consider adding one of the following versions in your config file at" "$closest_tool_version"
if [ -n "${preset_plugin_versions[*]}" ]; then
printf "%s %s\n" "No preset version installed for command" "$shim_name"
printf "%s\n\n" "Please install a version by running one of the following:"
for preset_plugin_version in "${preset_plugin_versions[@]}"; do
printf "%s %s\n" "asdf install" "$preset_plugin_version"
done
printf "\n%s %s\n" "or add one of the following versions in your config file at" "$closest_tool_version"
shim_plugin_versions "${shim_name}"
else
printf "%s %s\n" "No version is set for command" "$shim_name"
printf "%s %s\n" "Consider adding one of the following versions in your config file at" "$closest_tool_version"
shim_plugin_versions "${shim_name}"
fi
fi
shim_plugin_versions "${shim_name}"
) >&2

return 126
Expand Down
23 changes: 23 additions & 0 deletions test/shim_exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ teardown() {
echo "$output" | grep -q "dummy 1.0" 2>/dev/null
}

@test "shim exec should suggest to check obsolete shim" {
# Install 1.0, with fake "dummyman" command, shimmed for 1.0
run asdf install dummy 1.0
echo "echo Dummy Manager" >"$ASDF_DIR/installs/dummy/1.0/bin/dummyman"
chmod +x "$ASDF_DIR/installs/dummy/1.0/bin/dummyman"
run asdf reshim dummy 1.0

# Install 1.3
run asdf install dummy 1.3
echo "dummy 1.3" >"$PROJECT_DIR/.tool-versions"

# reshim doesn't help
run asdf reshim dummy
run asdf shim-versions dummyman
[ "$status" -eq 0 ]
[ "$output" = "dummy 1.0" ]
run "$ASDF_DIR/shims/dummyman"
[ "$status" -eq 126 ]

echo "$output" | grep -q "Shimmed command 'dummyman' has no matched plugin version" 2>/dev/null
echo "$output" | grep -q "Check the executable or try install dummyman for your preset plugin version" 2>/dev/null
}

@test "shim exec should execute first plugin that is installed and set" {
run asdf install dummy 2.0.0
run asdf install dummy 3.0
Expand Down