[Refactor] minor "if" and "return" improvement
parent
2ec2d31012
commit
e87f395b7a
45
nvm.sh
45
nvm.sh
|
@ -205,18 +205,16 @@ nvm_rc_version() {
|
||||||
export NVM_RC_VERSION=''
|
export NVM_RC_VERSION=''
|
||||||
local NVMRC_PATH
|
local NVMRC_PATH
|
||||||
NVMRC_PATH="$(nvm_find_nvmrc)"
|
NVMRC_PATH="$(nvm_find_nvmrc)"
|
||||||
if [ -e "${NVMRC_PATH}" ]; then
|
if [ ! -e "${NVMRC_PATH}" ]; then
|
||||||
read -r NVM_RC_VERSION < "${NVMRC_PATH}" || printf ''
|
|
||||||
if [ -n "${NVM_RC_VERSION}" ]; then
|
|
||||||
nvm_echo "Found '${NVMRC_PATH}' with version <${NVM_RC_VERSION}>"
|
|
||||||
else
|
|
||||||
nvm_err "Warning: empty .nvmrc file found at \"${NVMRC_PATH}\""
|
|
||||||
return 2
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
nvm_err "No .nvmrc file found"
|
nvm_err "No .nvmrc file found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
read -r NVM_RC_VERSION < "${NVMRC_PATH}" || printf ''
|
||||||
|
if [ ! -n "${NVM_RC_VERSION}" ]; then
|
||||||
|
nvm_err "Warning: empty .nvmrc file found at \"${NVMRC_PATH}\""
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
nvm_echo "Found '${NVMRC_PATH}' with version <${NVM_RC_VERSION}>"
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_clang_version() {
|
nvm_clang_version() {
|
||||||
|
@ -341,9 +339,8 @@ nvm_version() {
|
||||||
if [ -z "${VERSION}" ] || [ "_${VERSION}" = "_N/A" ]; then
|
if [ -z "${VERSION}" ] || [ "_${VERSION}" = "_N/A" ]; then
|
||||||
nvm_echo "N/A"
|
nvm_echo "N/A"
|
||||||
return 3;
|
return 3;
|
||||||
else
|
|
||||||
nvm_echo "${VERSION}"
|
|
||||||
fi
|
fi
|
||||||
|
nvm_echo "${VERSION}"
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_remote_version() {
|
nvm_remote_version() {
|
||||||
|
@ -1261,10 +1258,9 @@ nvm_checksum() {
|
||||||
elif [ -z "${2-}" ]; then
|
elif [ -z "${2-}" ]; then
|
||||||
nvm_echo 'Checksums empty' #missing in raspberry pi binary
|
nvm_echo 'Checksums empty' #missing in raspberry pi binary
|
||||||
return
|
return
|
||||||
else
|
fi
|
||||||
nvm_err 'Checksums do not match.'
|
nvm_err 'Checksums do not match.'
|
||||||
return 1
|
return 1
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_print_versions() {
|
nvm_print_versions() {
|
||||||
|
@ -1540,8 +1536,7 @@ nvm_ensure_default_set() {
|
||||||
if [ -z "$VERSION" ]; then
|
if [ -z "$VERSION" ]; then
|
||||||
nvm_err 'nvm_ensure_default_set: a version is required'
|
nvm_err 'nvm_ensure_default_set: a version is required'
|
||||||
return 1
|
return 1
|
||||||
fi
|
elif nvm_alias default >/dev/null 2>&1; then
|
||||||
if nvm_alias default >/dev/null 2>&1; then
|
|
||||||
# default already set
|
# default already set
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
@ -1918,7 +1913,7 @@ nvm_install_source() {
|
||||||
TARBALL="$(nvm_download_artifact "${FLAVOR}" source "${TYPE}" "${VERSION}" | command tail -1)" && \
|
TARBALL="$(nvm_download_artifact "${FLAVOR}" source "${TYPE}" "${VERSION}" | command tail -1)" && \
|
||||||
[ -f "${TARBALL}" ] && \
|
[ -f "${TARBALL}" ] && \
|
||||||
TMPDIR="$(dirname "${TARBALL}")/files" && \
|
TMPDIR="$(dirname "${TARBALL}")/files" && \
|
||||||
if (
|
if ! (
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
command mkdir -p "${TMPDIR}" && \
|
command mkdir -p "${TMPDIR}" && \
|
||||||
command "${tar}" -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" --strip-components 1 && \
|
command "${tar}" -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" --strip-components 1 && \
|
||||||
|
@ -1930,12 +1925,10 @@ nvm_install_source() {
|
||||||
command rm -f "${VERSION_PATH}" 2>/dev/null && \
|
command rm -f "${VERSION_PATH}" 2>/dev/null && \
|
||||||
$make -j "${NVM_MAKE_JOBS}" ${MAKE_CXX-} install
|
$make -j "${NVM_MAKE_JOBS}" ${MAKE_CXX-} install
|
||||||
); then
|
); then
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
nvm_err "nvm: install ${VERSION} failed!"
|
nvm_err "nvm: install ${VERSION} failed!"
|
||||||
command rm -rf "${TMPDIR-}"
|
command rm -rf "${TMPDIR-}"
|
||||||
return 1
|
return 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_use_if_needed() {
|
nvm_use_if_needed() {
|
||||||
|
@ -2031,9 +2024,7 @@ nvm_die_on_prefix() {
|
||||||
nvm_err "nvm is not compatible with the \"NPM_CONFIG_PREFIX\" environment variable: currently set to \"$NPM_CONFIG_PREFIX\""
|
nvm_err "nvm is not compatible with the \"NPM_CONFIG_PREFIX\" environment variable: currently set to \"$NPM_CONFIG_PREFIX\""
|
||||||
nvm_err 'Run `unset NPM_CONFIG_PREFIX` to unset it.'
|
nvm_err 'Run `unset NPM_CONFIG_PREFIX` to unset it.'
|
||||||
return 4
|
return 4
|
||||||
fi
|
elif ! nvm_has 'npm'; then
|
||||||
|
|
||||||
if ! nvm_has 'npm'; then
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -2378,13 +2369,11 @@ nvm() {
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
nvm_rc_version
|
nvm_rc_version
|
||||||
if [ $version_not_provided -eq 1 ]; then
|
if [ $version_not_provided -eq 1 ] && [ -z "$NVM_RC_VERSION" ]; then
|
||||||
if [ -z "$NVM_RC_VERSION" ]; then
|
|
||||||
unset NVM_RC_VERSION
|
unset NVM_RC_VERSION
|
||||||
>&2 nvm --help
|
>&2 nvm --help
|
||||||
return 127
|
return 127
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
provided_version="$NVM_RC_VERSION"
|
provided_version="$NVM_RC_VERSION"
|
||||||
unset NVM_RC_VERSION
|
unset NVM_RC_VERSION
|
||||||
fi
|
fi
|
||||||
|
@ -3003,10 +2992,9 @@ nvm() {
|
||||||
if [ -n "$NVM_OUTPUT" ]; then
|
if [ -n "$NVM_OUTPUT" ]; then
|
||||||
NVM_NO_COLORS="${NVM_NO_COLORS-}" nvm_print_versions "$NVM_OUTPUT"
|
NVM_NO_COLORS="${NVM_NO_COLORS-}" nvm_print_versions "$NVM_OUTPUT"
|
||||||
return $EXIT_CODE
|
return $EXIT_CODE
|
||||||
else
|
fi
|
||||||
NVM_NO_COLORS="${NVM_NO_COLORS-}" nvm_print_versions "N/A"
|
NVM_NO_COLORS="${NVM_NO_COLORS-}" nvm_print_versions "N/A"
|
||||||
return 3
|
return 3
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
"current" )
|
"current" )
|
||||||
nvm_version current
|
nvm_version current
|
||||||
|
@ -3040,10 +3028,9 @@ nvm() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
else
|
fi
|
||||||
nvm_err 'System version of node not found.'
|
nvm_err 'System version of node not found.'
|
||||||
return 127
|
return 127
|
||||||
fi
|
|
||||||
elif [ "_$VERSION" = "_∞" ]; then
|
elif [ "_$VERSION" = "_∞" ]; then
|
||||||
nvm_err "The alias \"$2\" leads to an infinite loop. Aborting."
|
nvm_err "The alias \"$2\" leads to an infinite loop. Aborting."
|
||||||
return 8
|
return 8
|
||||||
|
|
Loading…
Reference in New Issue