nvm run: use common code path for "ensure version installed"

Jordan Harband 2015-10-07 18:08:48 -07:00
parent 20f4acdd25
commit cb033adc6f
2 changed files with 14 additions and 7 deletions

17
nvm.sh
View File

@ -1846,7 +1846,7 @@ nvm() {
fi fi
fi fi
provided_version=$1 provided_version="$1"
if [ -n "$provided_version" ]; then if [ -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
@ -1860,6 +1860,16 @@ nvm() {
fi fi
fi fi
if [ -n "$NVM_RC_VERSION" ]; then
nvm_ensure_version_installed "$NVM_RC_VERSION"
else
nvm_ensure_version_installed "$provided_version"
fi
EXIT_CODE=$?
if [ "$EXIT_CODE" != "0" ]; then
return $EXIT_CODE
fi
local NVM_IOJS local NVM_IOJS
if nvm_is_iojs_version "$VERSION"; then if nvm_is_iojs_version "$VERSION"; then
NVM_IOJS=true NVM_IOJS=true
@ -1876,10 +1886,7 @@ nvm() {
ZHS_HAS_SHWORDSPLIT_UNSET=$(setopt | command grep shwordsplit > /dev/null ; echo $?) ZHS_HAS_SHWORDSPLIT_UNSET=$(setopt | command grep shwordsplit > /dev/null ; echo $?)
setopt shwordsplit setopt shwordsplit
fi fi
if [ "_$VERSION" = "_N/A" ]; then if [ -z "$ARGS" ]; then
echo "$(nvm_ensure_version_prefix "$provided_version") is not installed yet" >&2
EXIT_CODE=1
elif [ -z "$ARGS" ]; then
if [ "$NVM_IOJS" = true ]; then if [ "$NVM_IOJS" = true ]; then
nvm exec "$VERSION" iojs nvm exec "$VERSION" iojs
else else

View File

@ -5,5 +5,5 @@ die () { echo $@ ; exit 1; }
. ../../../nvm.sh . ../../../nvm.sh
[ "$(nvm run 0.2 --version 2>&1)" = "v0.2 is not installed yet" ] || die "\`nvm run\` with an uninstalled node version failed to error out correctly" [ "$(nvm run 0.2 --version 2>&1)" = 'N/A: version "v0.2" is not yet installed' ] || die "\`nvm run\` with an uninstalled node version failed to error out correctly"
[ "$(nvm run iojs-0.2 --version 2>&1)" = "iojs-v0.2 is not installed yet" ] || die "\`nvm run\` with an uninstalled iojs version failed to error out correctly" [ "$(nvm run iojs-0.2 --version 2>&1)" = 'N/A: version "iojs-v0.2" is not yet installed' ] || die "\`nvm run\` with an uninstalled iojs version failed to error out correctly"