Add --unset option to shell command

This commit is contained in:
OZAWA Sakuro 2019-08-17 22:46:00 +09:00
parent 069db7d6d3
commit 503263a68d
2 changed files with 18 additions and 5 deletions

View File

@ -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\"";;

View File

@ -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"