mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Add --unset option to shell command
This commit is contained in:
parent
069db7d6d3
commit
503263a68d
@ -81,7 +81,7 @@ global_command() {
|
||||
# Output from this command must be executable shell code
|
||||
shell_command() {
|
||||
if [ "$#" -lt "2" ]; then
|
||||
echo "Usage: asdf shell <name> <version>" >&2
|
||||
echo "Usage: asdf shell <name> <version> | --unset" >&2
|
||||
echo 'false'
|
||||
exit 1
|
||||
fi
|
||||
@ -89,15 +89,19 @@ shell_command() {
|
||||
local plugin=$1
|
||||
local version=$2
|
||||
|
||||
local upcase_name
|
||||
upcase_name=$(echo "$plugin" | tr '[:lower:]-' '[:upper:]_')
|
||||
local version_env_var="ASDF_${upcase_name}_VERSION"
|
||||
|
||||
if [ "$version" = "--unset" ]; then
|
||||
echo "unset $version_env_var"
|
||||
exit 0
|
||||
fi
|
||||
if ! (check_if_version_exists "$plugin" "$version"); then
|
||||
echo 'false'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local upcase_name
|
||||
upcase_name=$(echo "$plugin" | tr '[:lower:]-' '[:upper:]_')
|
||||
local version_env_var="ASDF_${upcase_name}_VERSION"
|
||||
|
||||
case $ASDF_SHELL in
|
||||
fish )
|
||||
echo "set -gx $version_env_var \"$version\"";;
|
||||
|
@ -238,6 +238,15 @@ teardown() {
|
||||
unset ASDF_DUMMY_VERSION
|
||||
}
|
||||
|
||||
@test "shell wrapper function with --unset should unset ENV var" {
|
||||
source $(dirname "$BATS_TEST_DIRNAME")/asdf.sh
|
||||
asdf shell "dummy" "1.1.0"
|
||||
[ $(echo $ASDF_DUMMY_VERSION) = "1.1.0" ]
|
||||
asdf shell "dummy" "--unset"
|
||||
[ -z "$(echo $ASDF_DUMMY_VERSION)" ]
|
||||
unset ASDF_DUMMY_VERSION
|
||||
}
|
||||
|
||||
@test "shell wrapper function should return an error for missing plugins" {
|
||||
source $(dirname "$BATS_TEST_DIRNAME")/asdf.sh
|
||||
run asdf shell "nonexistent" "1.0.0"
|
||||
|
Loading…
Reference in New Issue
Block a user