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

View File

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