Add asdf shim-versions command (#380)

For example `asdf shim-versions npm` will list the plugins and their
versions on which the `npm` command is available.

Based on #432
This commit is contained in:
Victor Hugo Borja 2019-01-19 04:48:22 -06:00
parent 4766a2b0b2
commit 7fda291df0
5 changed files with 45 additions and 4 deletions

View File

@ -16,6 +16,8 @@ Features
slower `get_preset_version_for` which takes legacy formats into account.
* Shim exec recommends which plugins or versions to set when command is not found.
* `asdf reshim` without arguments now reshims all installed plugins (#407)
* Add `asdf shim-versions <executable>` to list on which plugins and versions is a command
available. (#380)
Fixed Bugs

View File

@ -17,6 +17,8 @@ source "$(dirname "$(dirname "$0")")/lib/commands/current.sh"
source "$(dirname "$(dirname "$0")")/lib/commands/where.sh"
# shellcheck source=lib/commands/which.sh
source "$(dirname "$(dirname "$0")")/lib/commands/which.sh"
# shellcheck source=lib/commands/shim_versions.sh
source "$(dirname "$(dirname "$0")")/lib/commands/shim_versions.sh"
# shellcheck source=lib/commands/version_commands.sh
source "$(dirname "$(dirname "$0")")/lib/commands/version_commands.sh"
# shellcheck source=lib/commands/list.sh
@ -83,9 +85,6 @@ case $1 in
"list-all")
list_all_command $callback_args;;
"shim")
shim_command $callback_args;;
"reshim")
reshim_command $callback_args;;
@ -111,6 +110,8 @@ case $1 in
"plugin-test")
plugin_test_command $callback_args;;
"shim-versions")
shim_versions_command $callback_args;;
*)
help_command
exit 1;;

View File

@ -17,7 +17,7 @@ MANAGE PACKAGES
asdf current Display current version set or being used for all packages
asdf current <name> Display current version set or being used for package
asdf where <name> [<version>] Display install path for an installed or current version
asdf which <name> Display install path for current version
asdf which <executable> Display the path to an executable
asdf local <name> <version> Set the package local version
asdf global <name> <version> Set the package global version
asdf list <name> List installed versions of a package
@ -26,6 +26,7 @@ MANAGE PACKAGES
UTILS
asdf reshim <name> <version> Recreate shims for version of a package
asdf shim-versions <executable> List on which plugins and versions is an executable provided.
asdf update Update asdf to the latest stable release
asdf update --head Update asdf to the latest on the master branch

View File

@ -0,0 +1,4 @@
shim_versions_command() {
local shim_name=$1
shim_plugin_versions "$shim_name"
}

View File

@ -0,0 +1,33 @@
#!/usr/bin/env bats
load test_helpers
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/shim_versions.sh
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/reshim.sh
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh
setup() {
setup_asdf_dir
install_dummy_plugin
PROJECT_DIR=$HOME/project
mkdir -p $PROJECT_DIR
cd $PROJECT_DIR
}
teardown() {
clean_asdf_dir
}
@test "shim_versions_command should list plugins and versions where command is available" {
cd $PROJECT_DIR
run install_command dummy 3.0
run install_command dummy 1.0
run reshim_command dummy
run shim_versions_command dummy
[ "$status" -eq 0 ]
echo "$output" | grep "dummy 3.0"
echo "$output" | grep "dummy 1.0"
}