mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
parent
65ce0db5e1
commit
46e5f7427f
@ -1,51 +1,33 @@
|
||||
which_command() {
|
||||
local plugin_name=$1
|
||||
local command=$1
|
||||
local plugins_path
|
||||
plugins_path=$(get_plugin_path)
|
||||
|
||||
check_if_plugin_exists "$plugin_name"
|
||||
|
||||
local search_path
|
||||
search_path=$(pwd)
|
||||
local version_and_path
|
||||
version_and_path=$(find_version "$plugin_name" "$search_path")
|
||||
local version
|
||||
version=$(cut -d '|' -f 1 <<< "$version_and_path");
|
||||
local install_type="version"
|
||||
|
||||
check_if_version_exists "$plugin_name" "$version"
|
||||
check_for_deprecated_plugin "$plugin_name"
|
||||
|
||||
if [ -z "$version" ]; then
|
||||
display_no_version_set "$plugin_name"
|
||||
exit 1
|
||||
if ls "$plugins_path" &> /dev/null; then
|
||||
for plugin_path in "$plugins_path"/* ; do
|
||||
plugin_name=$(basename "$plugin_path")
|
||||
full_version=$(get_preset_version_for "$plugin_name")
|
||||
IFS=' ' read -a versions <<< "$full_version"
|
||||
for version in "${versions[@]}"; do
|
||||
if [ -f "${plugin_path}/bin/exec-path" ]; then
|
||||
echo "EXEC_PATH"
|
||||
cmd=$(basename "$executable_path")
|
||||
executable_path="$("${plugin_path}/bin/exec-path" "$install_path" "$cmd" "$executable_path")"
|
||||
fi
|
||||
full_executable_path=$(get_executable_path "$plugin_name" "$version" "$executable_path")
|
||||
local location=$(find $full_executable_path -name $command -type f -perm -u+x | sed -e 's|//|/|g')
|
||||
if [ ! -z "$location" ]; then
|
||||
echo $location
|
||||
not_found=0
|
||||
else
|
||||
not_found=1
|
||||
fi
|
||||
done
|
||||
done
|
||||
if [ $not_found -eq 1 ]; then
|
||||
echo "No executable binary found for $command"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
local install_path
|
||||
install_path=$(get_install_path "$plugin_name" "$install_type" "$version")
|
||||
|
||||
if [ -d "$install_path" ]; then
|
||||
echo "$install_path/bin/$plugin_name"
|
||||
exit 0
|
||||
else
|
||||
echo "Version not installed"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Warn if the plugin isn't using the updated legacy file api.
|
||||
check_for_deprecated_plugin() {
|
||||
local plugin_name=$1
|
||||
|
||||
local plugin_path
|
||||
plugin_path=$(get_plugin_path "$plugin_name")
|
||||
local legacy_config
|
||||
legacy_config=$(get_asdf_config_value "legacy_version_file")
|
||||
local deprecated_script="${plugin_path}/bin/get-version-from-legacy-file"
|
||||
local new_script="${plugin_path}/bin/list-legacy-filenames"
|
||||
|
||||
if [ "$legacy_config" = "yes" ] && [ -f "$deprecated_script" ] && [ ! -f "$new_script" ]; then
|
||||
echo "Heads up! It looks like your $plugin_name plugin is out of date. You can update it with:"
|
||||
echo ""
|
||||
echo " asdf plugin-update $plugin_name"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
exit 0
|
||||
}
|
6
test/fixtures/dummy_plugin/bin/install
vendored
6
test/fixtures/dummy_plugin/bin/install
vendored
@ -10,4 +10,8 @@ cat <<EOF > "$ASDF_INSTALL_PATH/bin/dummy"
|
||||
echo This is Dummy ${ASDF_INSTALL_VERSION}! \$2 \$1
|
||||
EOF
|
||||
chmod +x "$ASDF_INSTALL_PATH/bin/dummy"
|
||||
mkdir -p "$ASDF_INSTALL_PATH/bin/subdir"
|
||||
mkdir -p "$ASDF_INSTALL_PATH/bin/subdir"
|
||||
cat <<EOF > "$ASDF_INSTALL_PATH/bin/subdir/other_bin"
|
||||
echo This is Other Bin ${ASDF_INSTALL_VERSION}! \$2 \$1
|
||||
EOF
|
||||
chmod +x "$ASDF_INSTALL_PATH/bin/subdir/other_bin"
|
@ -8,40 +8,37 @@ load test_helpers
|
||||
setup() {
|
||||
setup_asdf_dir
|
||||
install_dummy_plugin
|
||||
install_mock_plugin "bazbat"
|
||||
run install_command dummy 1.0
|
||||
|
||||
PROJECT_DIR=$HOME/project
|
||||
mkdir $PROJECT_DIR
|
||||
echo 'dummy 1.0' >> $PROJECT_DIR/.tool-versions
|
||||
}
|
||||
|
||||
teardown() {
|
||||
clean_asdf_dir
|
||||
}
|
||||
|
||||
@test "which should show dummy 1.0 main binary path" {
|
||||
@test "which should show dummy 1.0 main binary" {
|
||||
cd $PROJECT_DIR
|
||||
|
||||
echo 'dummy 1.0' >> $PROJECT_DIR/.tool-versions
|
||||
|
||||
run which_command "dummy"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/dummy" ]
|
||||
}
|
||||
|
||||
@test "which should inform when no version is set" {
|
||||
@test "which should show dummy 1.0 other binary" {
|
||||
cd $PROJECT_DIR
|
||||
|
||||
local expected
|
||||
expected="No version set for bazbat; please run \`asdf <global | local> bazbat <version>\`"
|
||||
run which_command "other_bin"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/subdir/other_bin" ]
|
||||
}
|
||||
|
||||
@test "which should inform when no binary is found" {
|
||||
cd $PROJECT_DIR
|
||||
|
||||
run which_command "bazbat"
|
||||
[ "$status" -eq 1 ]
|
||||
[ "$output" = "$expected" ]
|
||||
}
|
||||
|
||||
@test "which should error when the plugin doesn't exist" {
|
||||
run which_command "foobar"
|
||||
[ "$status" -eq 1 ]
|
||||
[ "$output" = "No such plugin: foobar" ]
|
||||
[ "$output" = "No executable binary found for bazbat" ]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user