[Fix] `nvm ls`/`nvm alias`/`nvm_list_aliases`: zsh: when no LTS aliases, no error

Fixes #2575.
Jordan Harband 2021-09-01 10:06:32 -07:00
parent fd78c0101e
commit 5b77f7d023
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
3 changed files with 24 additions and 5 deletions

1
nvm.sh
View File

@ -957,6 +957,7 @@ nvm_list_aliases() {
NVM_ALIAS_DIR="$(nvm_alias_path)" NVM_ALIAS_DIR="$(nvm_alias_path)"
command mkdir -p "${NVM_ALIAS_DIR}/lts" command mkdir -p "${NVM_ALIAS_DIR}/lts"
nvm_is_zsh && unsetopt local_options nomatch
( (
local ALIAS_PATH local ALIAS_PATH
for ALIAS_PATH in "${NVM_ALIAS_DIR}/${ALIAS}"*; do for ALIAS_PATH in "${NVM_ALIAS_DIR}/${ALIAS}"*; do

View File

@ -2,10 +2,7 @@
\. ../../../nvm.sh \. ../../../nvm.sh
die () { die () { echo "$@" ; exit 1; }
echo "nvm_list_aliases did not call nvm_get_colors. Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
exit 1
}
set -e set -e
@ -22,4 +19,4 @@ OUTPUT=$(command printf %b $(nvm_list_aliases test-stable-1) | awk '{ print subs
EXPECTED_OUTPUT=$(command printf %b "\033[0;95mtest-stable-1" | awk '{ print substr($0, 1, 19); }') EXPECTED_OUTPUT=$(command printf %b "\033[0;95mtest-stable-1" | awk '{ print substr($0, 1, 19); }')
echo "\033[0m" echo "\033[0m"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "nvm_list_aliases did not call nvm_get_colors. Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"

View File

@ -0,0 +1,21 @@
#!/bin/sh
\. ../../../nvm.sh
die () {
mv "$(nvm_alias_path)/_lts.bak" "$(nvm_alias_path)/lts"
echo "$@"
exit 1
}
set -e
nvm_alias_path() {
nvm_echo "../../../alias"
}
mv "$(nvm_alias_path)/lts" "$(nvm_alias_path)/_lts.bak"
STDERR_OUTPUT="$(nvm_list_aliases 2>&1 >/dev/null)"
[ -z "${STDERR_OUTPUT}" ] || die "expected no stderr output, got >${STDERR_OUTPUT}<"