Skip to content

Commit 759f70f

Browse files
committed
[Refactor] prefer case over if/else chains
1 parent 06a9179 commit 759f70f

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

nvm.sh

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,11 +1415,11 @@ nvm_add_iojs_prefix() {
14151415
nvm_strip_iojs_prefix() {
14161416
local NVM_IOJS_PREFIX
14171417
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
1418-
if [ "${1-}" = "${NVM_IOJS_PREFIX}" ]; then
1419-
nvm_echo
1420-
else
1421-
nvm_echo "${1#"${NVM_IOJS_PREFIX}"-}"
1422-
fi
1418+
1419+
case "${1-}" in
1420+
"${NVM_IOJS_PREFIX}") nvm_echo ;;
1421+
*) nvm_echo "${1#"${NVM_IOJS_PREFIX}"-}" ;;
1422+
esac
14231423
}
14241424

14251425
nvm_ls() {
@@ -1551,12 +1551,15 @@ nvm_ls() {
15511551
fi
15521552

15531553
if [ "${NVM_ADD_SYSTEM-}" = true ]; then
1554-
if [ -z "${PATTERN}" ] || [ "${PATTERN}" = 'v' ]; then
1555-
VERSIONS="${VERSIONS}
1554+
case "${PATTERN}" in
1555+
'' | v)
1556+
VERSIONS="${VERSIONS}
15561557
system"
1557-
elif [ "${PATTERN}" = 'system' ]; then
1558-
VERSIONS="system"
1559-
fi
1558+
;;
1559+
system)
1560+
VERSIONS="system"
1561+
;;
1562+
esac
15601563
fi
15611564

15621565
if [ -z "${VERSIONS}" ]; then
@@ -1690,7 +1693,7 @@ EOF
16901693
LTS="${LTS#lts/}"
16911694
fi
16921695

1693-
VERSIONS="$({ command awk -v lts="${LTS-}" '{
1696+
VERSIONS="$( { command awk -v lts="${LTS-}" '{
16941697
if (!$1) { next }
16951698
if (lts && $10 ~ /^\-?$/) { next }
16961699
if (lts && lts != "*" && tolower($10) !~ tolower(lts)) { next }

0 commit comments

Comments
 (0)