`nvm run`: add `--lts`/`--lts=argon` support

Jordan Harband 2016-05-04 00:29:37 -07:00
parent 45627d0a40
commit 859be3f6a1
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
1 changed files with 28 additions and 18 deletions

46
nvm.sh
View File

@ -1847,6 +1847,8 @@ nvm() {
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.' nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.' nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
nvm_echo ' nvm run [--silent] <version> [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available' nvm_echo ' nvm run [--silent] <version> [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available'
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
nvm_echo ' nvm current Display currently activated version' nvm_echo ' nvm current Display currently activated version'
nvm_echo ' nvm ls List installed versions' nvm_echo ' nvm ls List installed versions'
nvm_echo ' nvm ls <version> List versions matching a given <version>' nvm_echo ' nvm ls <version> List versions matching a given <version>'
@ -2332,10 +2334,13 @@ nvm() {
shift shift
local NVM_SILENT local NVM_SILENT
local NVM_LTS
while [ $# -gt 0 ] while [ $# -gt 0 ]
do do
case "$1" in case "$1" in
--silent) NVM_SILENT='--silent' ; shift ;; --silent) NVM_SILENT='--silent' ; shift ;;
--lts) NVM_LTS='*' ; shift ;;
--lts=*) NVM_LTS="${1##--lts=}" ; shift ;;
*) *)
if [ -n "$1" ]; then if [ -n "$1" ]; then
break break
@ -2346,7 +2351,7 @@ nvm() {
esac esac
done done
if [ $# -lt 1 ]; then if [ $# -lt 1 ] && [ -z "${NVM_LTS-}" ]; then
if [ -n "${NVM_SILENT-}" ]; then if [ -n "${NVM_SILENT-}" ]; then
nvm_rc_version >/dev/null 2>&1 && has_checked_nvmrc=1 nvm_rc_version >/dev/null 2>&1 && has_checked_nvmrc=1
else else
@ -2354,30 +2359,30 @@ nvm() {
fi fi
if [ -n "$NVM_RC_VERSION" ]; then if [ -n "$NVM_RC_VERSION" ]; then
VERSION="$(nvm_version "$NVM_RC_VERSION" || return 0)" VERSION="$(nvm_version "$NVM_RC_VERSION" || return 0)"
else
VERSION='N/A'
fi fi
if [ $VERSION = "N/A" ]; then if [ "${VERSION:-N/A}" = 'N/A' ]; then
>&2 nvm --help >&2 nvm --help
return 127 return 127
fi fi
fi fi
provided_version="$1" if [ -z "${NVM_LTS-}" ]; then
if [ -n "$provided_version" ]; then provided_version="$1"
VERSION="$(nvm_version "$provided_version" || return 0)" if [ -n "$provided_version" ]; then
if [ "_$VERSION" = "_N/A" ] && ! nvm_is_valid_version "$provided_version"; then VERSION="$(nvm_version "$provided_version" || return 0)"
provided_version='' if [ "_${VERSION:-N/A}" = '_N/A' ] && ! nvm_is_valid_version "$provided_version"; then
if [ $has_checked_nvmrc -ne 1 ]; then provided_version=''
if [ $has_checked_nvmrc -ne 1 ]; then
if [ -n "${NVM_SILENT-}" ]; then if [ -n "${NVM_SILENT-}" ]; then
nvm_rc_version >/dev/null 2>&1 && has_checked_nvmrc=1 nvm_rc_version >/dev/null 2>&1 && has_checked_nvmrc=1
else else
nvm_rc_version && has_checked_nvmrc=1 nvm_rc_version && has_checked_nvmrc=1
fi
fi fi
VERSION="$(nvm_version "$NVM_RC_VERSION" || return 0)"
else
shift
fi fi
VERSION="$(nvm_version "$NVM_RC_VERSION" || return 0)"
else
shift
fi fi
fi fi
@ -2394,12 +2399,17 @@ nvm() {
ZSH_HAS_SHWORDSPLIT_UNSET="$(setopt | nvm_grep shwordsplit > /dev/null && nvm_echo $? || nvm_echo $?)" ZSH_HAS_SHWORDSPLIT_UNSET="$(setopt | nvm_grep shwordsplit > /dev/null && nvm_echo $? || nvm_echo $?)"
setopt shwordsplit setopt shwordsplit
fi fi
local LTS_ARG
if [ -n "${NVM_LTS-}" ]; then
LTS_ARG="--lts=${NVM_LTS-}"
VERSION=''
fi
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-}" "$VERSION" iojs "$@" nvm exec "${NVM_SILENT-}" "${LTS_ARG-}" "$VERSION" iojs "$@"
else else
nvm exec "${NVM_SILENT-}" "$VERSION" node "$@" nvm exec "${NVM_SILENT-}" "${LTS_ARG-}" "$VERSION" node "$@"
fi fi
EXIT_CODE="$?" EXIT_CODE="$?"
if [ "$ZSH_HAS_SHWORDSPLIT_UNSET" -eq 1 ] && nvm_has "unsetopt"; then if [ "$ZSH_HAS_SHWORDSPLIT_UNSET" -eq 1 ] && nvm_has "unsetopt"; then