Skip to content

Commit

Permalink
[Refactor] prefer case over if/else chains
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 5, 2025
1 parent 8283b91 commit 08c7103
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1417,11 +1417,11 @@ nvm_add_iojs_prefix() {
nvm_strip_iojs_prefix() {
local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
if [ "${1-}" = "${NVM_IOJS_PREFIX}" ]; then
nvm_echo
else
nvm_echo "${1#"${NVM_IOJS_PREFIX}"-}"
fi

case "${1-}" in
"${NVM_IOJS_PREFIX}") nvm_echo ;;
*) nvm_echo "${1#"${NVM_IOJS_PREFIX}"-}" ;;
esac
}

nvm_ls() {
Expand Down Expand Up @@ -1553,12 +1553,15 @@ nvm_ls() {
fi

if [ "${NVM_ADD_SYSTEM-}" = true ]; then
if [ -z "${PATTERN}" ] || [ "${PATTERN}" = 'v' ]; then
VERSIONS="${VERSIONS}
case "${PATTERN}" in
'' | v)
VERSIONS="${VERSIONS}
system"
elif [ "${PATTERN}" = 'system' ]; then
VERSIONS="system"
fi
;;
system)
VERSIONS="system"
;;
esac
fi

if [ -z "${VERSIONS}" ]; then
Expand Down Expand Up @@ -1692,7 +1695,7 @@ EOF
LTS="${LTS#lts/}"
fi

VERSIONS="$({ command awk -v lts="${LTS-}" '{
VERSIONS="$( { command awk -v lts="${LTS-}" '{
if (!$1) { next }
if (lts && $10 ~ /^\-?$/) { next }
if (lts && lts != "*" && tolower($10) !~ tolower(lts)) { next }
Expand Down

0 comments on commit 08c7103

Please sign in to comment.