[Refactor] `nvm run`/`nvm exec`: use `NVM_SILENT` consistently internally

Jordan Harband 2020-08-13 14:37:41 -07:00
parent 1c00753fd9
commit 9dc6f3e4a5
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
1 changed files with 13 additions and 20 deletions

33
nvm.sh
View File

@ -3155,10 +3155,15 @@ nvm() {
# run given version of node # run given version of node
local NVM_SILENT local NVM_SILENT
local NVM_SILENT_ARG
local NVM_LTS local NVM_LTS
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
--silent) NVM_SILENT='--silent' ; shift ;; --silent)
NVM_SILENT=1
NVM_SILENT_ARG='--silent'
shift
;;
--lts) NVM_LTS='*' ; shift ;; --lts) NVM_LTS='*' ; shift ;;
--lts=*) NVM_LTS="${1##--lts=}" ; shift ;; --lts=*) NVM_LTS="${1##--lts=}" ; shift ;;
*) *)
@ -3172,11 +3177,7 @@ nvm() {
done done
if [ $# -lt 1 ] && [ -z "${NVM_LTS-}" ]; then if [ $# -lt 1 ] && [ -z "${NVM_LTS-}" ]; then
if [ -n "${NVM_SILENT-}" ]; then NVM_SILENT="${NVM_SILENT:-0}" nvm_rc_version && has_checked_nvmrc=1
nvm_rc_version >/dev/null 2>&1 && has_checked_nvmrc=1
else
nvm_rc_version && has_checked_nvmrc=1
fi
if [ -n "${NVM_RC_VERSION-}" ]; then if [ -n "${NVM_RC_VERSION-}" ]; then
VERSION="$(nvm_version "${NVM_RC_VERSION-}")" ||: VERSION="$(nvm_version "${NVM_RC_VERSION-}")" ||:
fi fi
@ -3194,11 +3195,7 @@ nvm() {
if [ "_${VERSION:-N/A}" = '_N/A' ] && ! nvm_is_valid_version "${provided_version}"; then if [ "_${VERSION:-N/A}" = '_N/A' ] && ! nvm_is_valid_version "${provided_version}"; then
provided_version='' provided_version=''
if [ $has_checked_nvmrc -ne 1 ]; then if [ $has_checked_nvmrc -ne 1 ]; then
if [ -n "${NVM_SILENT-}" ]; then NVM_SILENT="${NVM_SILENT:-0}" nvm_rc_version && has_checked_nvmrc=1
nvm_rc_version >/dev/null 2>&1 && has_checked_nvmrc=1
else
nvm_rc_version && has_checked_nvmrc=1
fi
fi fi
VERSION="$(nvm_version "${NVM_RC_VERSION}")" ||: VERSION="$(nvm_version "${NVM_RC_VERSION}")" ||:
unset NVM_RC_VERSION unset NVM_RC_VERSION
@ -3224,9 +3221,9 @@ nvm() {
if [ "_${VERSION}" = "_N/A" ]; then if [ "_${VERSION}" = "_N/A" ]; then
nvm_ensure_version_installed "${provided_version}" nvm_ensure_version_installed "${provided_version}"
elif [ "${NVM_IOJS}" = true ]; then elif [ "${NVM_IOJS}" = true ]; then
nvm exec "${NVM_SILENT-}" "${LTS_ARG-}" "${VERSION}" iojs "$@" nvm exec "${NVM_SILENT_ARG-}" "${LTS_ARG-}" "${VERSION}" iojs "$@"
else else
nvm exec "${NVM_SILENT-}" "${LTS_ARG-}" "${VERSION}" node "$@" nvm exec "${NVM_SILENT_ARG-}" "${LTS_ARG-}" "${VERSION}" node "$@"
fi fi
EXIT_CODE="$?" EXIT_CODE="$?"
return $EXIT_CODE return $EXIT_CODE
@ -3236,7 +3233,7 @@ nvm() {
local NVM_LTS local NVM_LTS
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
--silent) NVM_SILENT='--silent' ; shift ;; --silent) NVM_SILENT=1 ; shift ;;
--lts) NVM_LTS='*' ; shift ;; --lts) NVM_LTS='*' ; shift ;;
--lts=*) NVM_LTS="${1##--lts=}" ; shift ;; --lts=*) NVM_LTS="${1##--lts=}" ; shift ;;
--) break ;; --) break ;;
@ -3262,11 +3259,7 @@ nvm() {
elif [ -n "${provided_version}" ]; then elif [ -n "${provided_version}" ]; then
VERSION="$(nvm_version "${provided_version}")" ||: VERSION="$(nvm_version "${provided_version}")" ||:
if [ "_${VERSION}" = '_N/A' ] && ! nvm_is_valid_version "${provided_version}"; then if [ "_${VERSION}" = '_N/A' ] && ! nvm_is_valid_version "${provided_version}"; then
if [ -n "${NVM_SILENT-}" ]; then NVM_SILENT="${NVM_SILENT:-0}" nvm_rc_version && has_checked_nvmrc=1
nvm_rc_version >/dev/null 2>&1
else
nvm_rc_version
fi
provided_version="${NVM_RC_VERSION}" provided_version="${NVM_RC_VERSION}"
unset NVM_RC_VERSION unset NVM_RC_VERSION
VERSION="$(nvm_version "${provided_version}")" ||: VERSION="$(nvm_version "${provided_version}")" ||:
@ -3281,7 +3274,7 @@ nvm() {
return $EXIT_CODE return $EXIT_CODE
fi fi
if [ -z "${NVM_SILENT-}" ]; then if [ "${NVM_SILENT:-0}" -ne 1 ]; then
if [ "${NVM_LTS-}" = '*' ]; then if [ "${NVM_LTS-}" = '*' ]; then
nvm_echo "Running node latest LTS -> $(nvm_version "${VERSION}")$(nvm use --silent "${VERSION}" && nvm_print_npm_version)" nvm_echo "Running node latest LTS -> $(nvm_version "${VERSION}")$(nvm use --silent "${VERSION}" && nvm_print_npm_version)"
elif [ -n "${NVM_LTS-}" ]; then elif [ -n "${NVM_LTS-}" ]; then