[Refactor] prefer case over if/else chains

This commit is contained in:
Jordan Harband 2025-02-04 22:45:35 -08:00
parent 06a9179309
commit 759f70f196
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56

25
nvm.sh
View File

@ -1415,11 +1415,11 @@ nvm_add_iojs_prefix() {
nvm_strip_iojs_prefix() { nvm_strip_iojs_prefix() {
local NVM_IOJS_PREFIX local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)" NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
if [ "${1-}" = "${NVM_IOJS_PREFIX}" ]; then
nvm_echo case "${1-}" in
else "${NVM_IOJS_PREFIX}") nvm_echo ;;
nvm_echo "${1#"${NVM_IOJS_PREFIX}"-}" *) nvm_echo "${1#"${NVM_IOJS_PREFIX}"-}" ;;
fi esac
} }
nvm_ls() { nvm_ls() {
@ -1551,12 +1551,15 @@ nvm_ls() {
fi fi
if [ "${NVM_ADD_SYSTEM-}" = true ]; then if [ "${NVM_ADD_SYSTEM-}" = true ]; then
if [ -z "${PATTERN}" ] || [ "${PATTERN}" = 'v' ]; then case "${PATTERN}" in
VERSIONS="${VERSIONS} '' | v)
VERSIONS="${VERSIONS}
system" system"
elif [ "${PATTERN}" = 'system' ]; then ;;
VERSIONS="system" system)
fi VERSIONS="system"
;;
esac
fi fi
if [ -z "${VERSIONS}" ]; then if [ -z "${VERSIONS}" ]; then
@ -1690,7 +1693,7 @@ EOF
LTS="${LTS#lts/}" LTS="${LTS#lts/}"
fi fi
VERSIONS="$({ command awk -v lts="${LTS-}" '{ VERSIONS="$( { command awk -v lts="${LTS-}" '{
if (!$1) { next } if (!$1) { next }
if (lts && $10 ~ /^\-?$/) { next } if (lts && $10 ~ /^\-?$/) { next }
if (lts && lts != "*" && tolower($10) !~ tolower(lts)) { next } if (lts && lts != "*" && tolower($10) !~ tolower(lts)) { next }