mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
fix: Better handling with paths that include spaces (#1485)
This commit is contained in:
parent
05a8bb940a
commit
bbcbddcdd4
14
bin/asdf
14
bin/asdf
@ -49,7 +49,10 @@ find_asdf_cmd() {
|
|||||||
find_plugin_cmd() {
|
find_plugin_cmd() {
|
||||||
local ASDF_CMD_FILE args_offset
|
local ASDF_CMD_FILE args_offset
|
||||||
if [ -d "$(get_plugin_path "$1")/bin" ]; then
|
if [ -d "$(get_plugin_path "$1")/bin" ]; then
|
||||||
IFS=' ' read -r ASDF_CMD_FILE args_offset <<<"$(find_cmd "$(get_plugin_path "$1")/lib/commands" "${@:2}")"
|
local result=
|
||||||
|
result="$(find_cmd "$(get_plugin_path "$1")/lib/commands" "${@:2}")"
|
||||||
|
ASDF_CMD_FILE=${result% *}
|
||||||
|
args_offset=${result##* }
|
||||||
if [ -n "$ASDF_CMD_FILE" ]; then
|
if [ -n "$ASDF_CMD_FILE" ]; then
|
||||||
args_offset=$((args_offset + 1)) # since the first argument is the plugin name
|
args_offset=$((args_offset + 1)) # since the first argument is the plugin name
|
||||||
printf "%s %s\\n" "$ASDF_CMD_FILE" "$args_offset"
|
printf "%s %s\\n" "$ASDF_CMD_FILE" "$args_offset"
|
||||||
@ -65,9 +68,14 @@ asdf_cmd() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
IFS=' ' read -r ASDF_CMD_FILE args_offset <<<"$(find_asdf_cmd "$@")"
|
local result=
|
||||||
|
result="$(find_asdf_cmd "$@")"
|
||||||
|
ASDF_CMD_FILE=${result% *}
|
||||||
|
args_offset=${result##* }
|
||||||
if [ -z "$ASDF_CMD_FILE" ]; then
|
if [ -z "$ASDF_CMD_FILE" ]; then
|
||||||
IFS=' ' read -r ASDF_CMD_FILE args_offset <<<"$(find_plugin_cmd "$@")"
|
result="$(find_plugin_cmd "$@")"
|
||||||
|
ASDF_CMD_FILE=${result% *}
|
||||||
|
args_offset=${result##* }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -x "$ASDF_CMD_FILE" ]; then
|
if [ -x "$ASDF_CMD_FILE" ]; then
|
||||||
|
@ -21,7 +21,16 @@ plugin_remove_command() {
|
|||||||
rm -rf "$(asdf_data_dir)/installs/${plugin_name}"
|
rm -rf "$(asdf_data_dir)/installs/${plugin_name}"
|
||||||
rm -rf "$(asdf_data_dir)/downloads/${plugin_name}"
|
rm -rf "$(asdf_data_dir)/downloads/${plugin_name}"
|
||||||
|
|
||||||
grep -l "asdf-plugin: ${plugin_name}" "$(asdf_data_dir)"/shims/* 2>/dev/null | xargs rm -f
|
local is_nullglob_disabled=
|
||||||
|
shopt -q nullglob || is_nullglob_disabled=yes
|
||||||
|
shopt -s nullglob
|
||||||
|
for f in "$(asdf_data_dir)"/shims/*; do
|
||||||
|
if grep -q "asdf-plugin: ${plugin_name}" "$f"; then
|
||||||
|
rm -f "$f"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
[ "$is_nullglob_disabled" = 'yes' ] && shopt -u nullglob
|
||||||
|
unset -v is_nullglob_disabled
|
||||||
|
|
||||||
asdf_run_hook "post_asdf_plugin_remove" "$plugin_name"
|
asdf_run_hook "post_asdf_plugin_remove" "$plugin_name"
|
||||||
asdf_run_hook "post_asdf_plugin_remove_${plugin_name}"
|
asdf_run_hook "post_asdf_plugin_remove_${plugin_name}"
|
||||||
|
@ -206,7 +206,7 @@ find_versions() {
|
|||||||
local legacy_filenames=""
|
local legacy_filenames=""
|
||||||
|
|
||||||
if [ "$legacy_config" = "yes" ] && [ -f "$legacy_list_filenames_script" ]; then
|
if [ "$legacy_config" = "yes" ] && [ -f "$legacy_list_filenames_script" ]; then
|
||||||
legacy_filenames=$($legacy_list_filenames_script)
|
legacy_filenames=$("$legacy_list_filenames_script")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while [ "$search_path" != "/" ]; do
|
while [ "$search_path" != "/" ]; do
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
load test_helpers
|
load test_helpers
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
ASDF_BATS_SPACE_IN_PATH=true setup_asdf_dir
|
setup_asdf_dir
|
||||||
install_dummy_plugin
|
install_dummy_plugin
|
||||||
|
|
||||||
PROJECT_DIR="$HOME/project"
|
PROJECT_DIR="$HOME/project"
|
||||||
|
@ -206,6 +206,8 @@ teardown() {
|
|||||||
[ "$output" = "System" ]
|
[ "$output" = "System" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# NOTE: The name of this test is linked to a condition in `test_helpers.bash. See
|
||||||
|
# the 'setup_asdf_dir' function for details.
|
||||||
@test "shim exec should use path executable when specified version path:<path>" {
|
@test "shim exec should use path executable when specified version path:<path>" {
|
||||||
run asdf install dummy 1.0
|
run asdf install dummy 1.0
|
||||||
|
|
||||||
|
@ -6,11 +6,12 @@ bats_require_minimum_version 1.7.0
|
|||||||
. "$(dirname "$BATS_TEST_DIRNAME")"/lib/utils.bash
|
. "$(dirname "$BATS_TEST_DIRNAME")"/lib/utils.bash
|
||||||
|
|
||||||
setup_asdf_dir() {
|
setup_asdf_dir() {
|
||||||
if [ -n "${ASDF_BATS_SPACE_IN_PATH:-}" ]; then
|
if [ "$BATS_TEST_NAME" = 'test_shim_exec_should_use_path_executable_when_specified_version_path-3a-3cpath-3e' ]; then
|
||||||
BASE_DIR="$(mktemp -dt "asdf with spaces.XXXX")"
|
BASE_DIR="$(mktemp -dt "asdf_with_no_spaces.XXXX")"
|
||||||
else
|
else
|
||||||
BASE_DIR="$(mktemp -dt asdf.XXXX)"
|
BASE_DIR="$(mktemp -dt "asdf with spaces.XXXX")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
HOME="$BASE_DIR/home"
|
HOME="$BASE_DIR/home"
|
||||||
ASDF_DIR="$HOME/.asdf"
|
ASDF_DIR="$HOME/.asdf"
|
||||||
mkdir -p "$ASDF_DIR/plugins"
|
mkdir -p "$ASDF_DIR/plugins"
|
||||||
|
Loading…
Reference in New Issue
Block a user