Skip to content

Commit 7fda291

Browse files
committed
Add asdf shim-versions command (asdf-vm#380)
For example `asdf shim-versions npm` will list the plugins and their versions on which the `npm` command is available. Based on asdf-vm#432
1 parent 4766a2b commit 7fda291

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Features
1616
slower `get_preset_version_for` which takes legacy formats into account.
1717
* Shim exec recommends which plugins or versions to set when command is not found.
1818
* `asdf reshim` without arguments now reshims all installed plugins (#407)
19+
* Add `asdf shim-versions <executable>` to list on which plugins and versions is a command
20+
available. (#380)
1921

2022
Fixed Bugs
2123

bin/asdf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ source "$(dirname "$(dirname "$0")")/lib/commands/current.sh"
1717
source "$(dirname "$(dirname "$0")")/lib/commands/where.sh"
1818
# shellcheck source=lib/commands/which.sh
1919
source "$(dirname "$(dirname "$0")")/lib/commands/which.sh"
20+
# shellcheck source=lib/commands/shim_versions.sh
21+
source "$(dirname "$(dirname "$0")")/lib/commands/shim_versions.sh"
2022
# shellcheck source=lib/commands/version_commands.sh
2123
source "$(dirname "$(dirname "$0")")/lib/commands/version_commands.sh"
2224
# shellcheck source=lib/commands/list.sh
@@ -83,9 +85,6 @@ case $1 in
8385
"list-all")
8486
list_all_command $callback_args;;
8587

86-
"shim")
87-
shim_command $callback_args;;
88-
8988
"reshim")
9089
reshim_command $callback_args;;
9190

@@ -111,6 +110,8 @@ case $1 in
111110
"plugin-test")
112111
plugin_test_command $callback_args;;
113112

113+
"shim-versions")
114+
shim_versions_command $callback_args;;
114115
*)
115116
help_command
116117
exit 1;;

help.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ MANAGE PACKAGES
1717
asdf current Display current version set or being used for all packages
1818
asdf current <name> Display current version set or being used for package
1919
asdf where <name> [<version>] Display install path for an installed or current version
20-
asdf which <name> Display install path for current version
20+
asdf which <executable> Display the path to an executable
2121
asdf local <name> <version> Set the package local version
2222
asdf global <name> <version> Set the package global version
2323
asdf list <name> List installed versions of a package
@@ -26,6 +26,7 @@ MANAGE PACKAGES
2626

2727
UTILS
2828
asdf reshim <name> <version> Recreate shims for version of a package
29+
asdf shim-versions <executable> List on which plugins and versions is an executable provided.
2930
asdf update Update asdf to the latest stable release
3031
asdf update --head Update asdf to the latest on the master branch
3132

lib/commands/shim_versions.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
shim_versions_command() {
2+
local shim_name=$1
3+
shim_plugin_versions "$shim_name"
4+
}

test/shim_versions_command.bats

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bats
2+
3+
load test_helpers
4+
5+
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/shim_versions.sh
6+
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/reshim.sh
7+
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh
8+
9+
setup() {
10+
setup_asdf_dir
11+
install_dummy_plugin
12+
13+
PROJECT_DIR=$HOME/project
14+
mkdir -p $PROJECT_DIR
15+
cd $PROJECT_DIR
16+
}
17+
18+
teardown() {
19+
clean_asdf_dir
20+
}
21+
22+
@test "shim_versions_command should list plugins and versions where command is available" {
23+
cd $PROJECT_DIR
24+
run install_command dummy 3.0
25+
run install_command dummy 1.0
26+
run reshim_command dummy
27+
28+
run shim_versions_command dummy
29+
[ "$status" -eq 0 ]
30+
31+
echo "$output" | grep "dummy 3.0"
32+
echo "$output" | grep "dummy 1.0"
33+
}

0 commit comments

Comments
 (0)