Skip to content

Commit 83a0054

Browse files
committed
Provide dedicated message for obsolete shim case
When a shimmed command can't find usable plugin version, we used to do several detection then output suggestion to user. The original message assumes "preset" plugin version is not installed, which could be false when shimmed command has old `asdf-plugin:` version written, while not being updated when install newer plugin version. Here add small `preset_plugin_installed` flag to detect if any considered "missing" plugin is in fact exist. Print only simple message for it. Example output: Shimmed command 'yarn' has no matched plugin version Check the executable or try install yarn for your preset plugin version
1 parent 609bb89 commit 83a0054

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

Diff for: lib/utils.bash

+22-11
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ with_shim_executable() {
803803
(
804804
local preset_plugin_versions
805805
preset_plugin_versions=()
806+
local preset_plugin_installed=
806807
local closest_tool_version
807808
closest_tool_version=$(find_tool_versions)
808809

@@ -815,22 +816,32 @@ with_shim_executable() {
815816
IFS=' ' read -r -a shim_versions <<<"$version_string"
816817
local usable_plugin_versions
817818
for shim_version in "${shim_versions[@]}"; do
818-
preset_plugin_versions+=("$shim_plugin $shim_version")
819+
if grep -q "$shim_version" <<<"$(asdf list "$shim_plugin")"; then
820+
preset_plugin_installed="yes"
821+
else
822+
preset_plugin_versions+=("$shim_plugin $shim_version")
823+
fi
819824
done
820825
done
821826

822-
if [ -n "${preset_plugin_versions[*]}" ]; then
823-
printf "%s %s\n" "No preset version installed for command" "$shim_name"
824-
printf "%s\n\n" "Please install a version by running one of the following:"
825-
for preset_plugin_version in "${preset_plugin_versions[@]}"; do
826-
printf "%s %s\n" "asdf install" "$preset_plugin_version"
827-
done
828-
printf "\n%s %s\n" "or add one of the following versions in your config file at" "$closest_tool_version"
827+
if [ -n "$preset_plugin_installed" ]; then
828+
printf "%s '%s' %s\n" "Shimmed command" "$shim_name" "has no matched plugin version"
829+
printf "%s %s %s\n" "Check the executable or try install" "$shim_name" "for your preset plugin version"
829830
else
830-
printf "%s %s\n" "No version is set for command" "$shim_name"
831-
printf "%s %s\n" "Consider adding one of the following versions in your config file at" "$closest_tool_version"
831+
if [ -n "${preset_plugin_versions[*]}" ]; then
832+
printf "%s %s\n" "No preset version installed for command" "$shim_name"
833+
printf "%s\n\n" "Please install a version by running one of the following:"
834+
for preset_plugin_version in "${preset_plugin_versions[@]}"; do
835+
printf "%s %s\n" "asdf install" "$preset_plugin_version"
836+
done
837+
printf "\n%s %s\n" "or add one of the following versions in your config file at" "$closest_tool_version"
838+
shim_plugin_versions "${shim_name}"
839+
else
840+
printf "%s %s\n" "No version is set for command" "$shim_name"
841+
printf "%s %s\n" "Consider adding one of the following versions in your config file at" "$closest_tool_version"
842+
shim_plugin_versions "${shim_name}"
843+
fi
832844
fi
833-
shim_plugin_versions "${shim_name}"
834845
) >&2
835846

836847
return 126

Diff for: test/shim_exec.bats

+3-10
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ teardown() {
129129
echo "$output" | grep -q "dummy 1.0" 2>/dev/null
130130
}
131131

132-
@test "issue #928" {
132+
@test "shim exec should suggest to check obsolete shim" {
133133
# Install 1.0, with fake "dummyman" command, shimmed for 1.0
134134
run asdf install dummy 1.0
135135
echo "echo Dummy Manager" >"$ASDF_DIR/installs/dummy/1.0/bin/dummyman"
@@ -138,25 +138,18 @@ teardown() {
138138

139139
# Install 1.3
140140
run asdf install dummy 1.3
141-
142141
echo "dummy 1.3" >"$PROJECT_DIR/.tool-versions"
143142

144143
# reshim doesn't help
145144
run asdf reshim dummy
146145
run asdf shim-versions dummyman
147146
[ "$status" -eq 0 ]
148147
[ "$output" = "dummy 1.0" ]
149-
150148
run "$ASDF_DIR/shims/dummyman"
151149
[ "$status" -eq 126 ]
152-
echo ">> $output" >&3
153150

154-
# Below is current (misleading) message
155-
echo "$output" | grep -q "No preset version installed for command dummyman" 2>/dev/null
156-
echo "$output" | grep -q "Please install a version by running one of the following:" 2>/dev/null
157-
echo "$output" | grep -q "asdf install dummy 1.3" 2>/dev/null
158-
echo "$output" | grep -q "or add one of the following versions in your config file at $PROJECT_DIR/.tool-versions" 2>/dev/null
159-
echo "$output" | grep -q "dummy 1.0" 2>/dev/null
151+
echo "$output" | grep -q "Shimmed command 'dummyman' has no matched plugin version" 2>/dev/null
152+
echo "$output" | grep -q "Check the executable or try install dummyman for your preset plugin version" 2>/dev/null
160153
}
161154

162155
@test "shim exec should execute first plugin that is installed and set" {

0 commit comments

Comments
 (0)