Add `--lts` support to `nvm version-remote`

Jordan Harband 2016-04-24 16:26:32 -07:00
parent 584bdd8ba3
commit 1d908d8256
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
2 changed files with 40 additions and 21 deletions

41
nvm.sh
View File

@ -308,14 +308,14 @@ nvm_remote_version() {
if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then
case "_$PATTERN" in case "_$PATTERN" in
"_$(nvm_iojs_prefix)") "_$(nvm_iojs_prefix)")
VERSION="$(nvm_ls_remote_iojs | command tail -1)" VERSION="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote_iojs | command tail -1)"
;; ;;
*) *)
VERSION="$(nvm_ls_remote "$PATTERN")" VERSION="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote "$PATTERN")"
;; ;;
esac esac
else else
VERSION="$(nvm_remote_versions "$PATTERN" | command tail -1)" VERSION="$(NVM_LTS="${NVM_LTS-}" nvm_remote_versions "$PATTERN" | command tail -1)"
fi fi
if [ -n "${NVM_VERSION_ONLY-}" ]; then if [ -n "${NVM_VERSION_ONLY-}" ]; then
command awk 'BEGIN { command awk 'BEGIN {
@ -337,18 +337,18 @@ nvm_remote_versions() {
PATTERN="$1" PATTERN="$1"
case "_$PATTERN" in case "_$PATTERN" in
"_$NVM_IOJS_PREFIX" | "_io.js") "_$NVM_IOJS_PREFIX" | "_io.js")
VERSIONS="$(nvm_ls_remote_iojs)" VERSIONS="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote_iojs)"
;; ;;
"_$(nvm_node_prefix)") "_$(nvm_node_prefix)")
VERSIONS="$(nvm_ls_remote)" VERSIONS="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote)"
;; ;;
*) *)
if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then
nvm_err 'Implicit aliases are not supported in nvm_remote_versions.' nvm_err 'Implicit aliases are not supported in nvm_remote_versions.'
return 1 return 1
fi fi
VERSIONS="$(nvm_echo "$(nvm_ls_remote "$PATTERN") VERSIONS="$(nvm_echo "$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote "$PATTERN")
$(nvm_ls_remote_iojs "$PATTERN")" | nvm_grep -v "N/A" | command sed '/^$/d')" $(NVM_LTS=${NVM_LTS-} nvm_ls_remote_iojs "$PATTERN")" | nvm_grep -v "N/A" | command sed '/^$/d')"
;; ;;
esac esac
@ -852,7 +852,7 @@ nvm_ls_remote() {
local PATTERN local PATTERN
PATTERN="$1" PATTERN="$1"
if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then
PATTERN="$(nvm_ls_remote "$(nvm_print_implicit_alias remote "$PATTERN")" | command tail -1)" PATTERN="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote "$(nvm_print_implicit_alias remote "$PATTERN")" | command awk '{ print $1 }' | command tail -1)"
elif [ -n "$PATTERN" ]; then elif [ -n "$PATTERN" ]; then
PATTERN="$(nvm_ensure_version_prefix "$PATTERN")" PATTERN="$(nvm_ensure_version_prefix "$PATTERN")"
else else
@ -1817,6 +1817,7 @@ nvm() {
nvm_echo ' --lts When listing, only show LTS (long-term support) versions' nvm_echo ' --lts When listing, only show LTS (long-term support) versions'
nvm_echo ' nvm version <version> Resolve the given description to a single local version' nvm_echo ' nvm version <version> Resolve the given description to a single local version'
nvm_echo ' nvm version-remote <version> Resolve the given description to a single remote version' nvm_echo ' nvm version-remote <version> Resolve the given description to a single remote version'
nvm_echo ' --lts When listing, only select from LTS (long-term support) versions'
nvm_echo ' nvm deactivate Undo effects of `nvm` on current shell' nvm_echo ' nvm deactivate Undo effects of `nvm` on current shell'
nvm_echo ' nvm alias [<pattern>] Show all aliases beginning with <pattern>' nvm_echo ' nvm alias [<pattern>] Show all aliases beginning with <pattern>'
nvm_echo ' nvm alias <name> <version> Set an alias named <name> pointing to <version>' nvm_echo ' nvm alias <name> <version> Set an alias named <name> pointing to <version>'
@ -2444,8 +2445,8 @@ nvm() {
NVM_LS_REMOTE_IOJS_EXIT_CODE=0 NVM_LS_REMOTE_IOJS_EXIT_CODE=0
local NVM_LS_REMOTE_IOJS_OUTPUT local NVM_LS_REMOTE_IOJS_OUTPUT
NVM_LS_REMOTE_IOJS_OUTPUT='' NVM_LS_REMOTE_IOJS_OUTPUT=''
if [ "_$NVM_FLAVOR" != "_$NVM_NODE_PREFIX" ]; then if [ "_$NVM_FLAVOR" != "_$NVM_NODE_PREFIX" ] && [ -z "${LTS-}" ]; then
NVM_LS_REMOTE_IOJS_OUTPUT=$(NVM_LTS="${LTS-}" nvm_ls_remote_iojs "$PATTERN") NVM_LS_REMOTE_IOJS_OUTPUT=$(nvm_ls_remote_iojs "$PATTERN")
NVM_LS_REMOTE_IOJS_EXIT_CODE=$? NVM_LS_REMOTE_IOJS_EXIT_CODE=$?
fi fi
@ -2618,7 +2619,25 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')"
nvm_version "$2" nvm_version "$2"
;; ;;
"version-remote" ) "version-remote" )
NVM_VERSION_ONLY=true nvm_remote_version "$2" local NVM_LTS
local PATTERN
while [ $# -gt 1 ]
do
case "$2" in
--lts)
NVM_LTS='*'
;;
--*)
nvm_err "Unsupported option \"$2\"."
return 55;
;;
*)
PATTERN="${PATTERN:-$2}"
;;
esac
shift
done
NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}"
;; ;;
"--version" ) "--version" )
nvm_echo '0.31.2' nvm_echo '0.31.2'

View File

@ -26,34 +26,34 @@ EXIT_CODE="$(nvm_remote_version iojs-foo >/dev/null 2>&1 ; echo $?)"
nvm_ls_remote() { nvm_ls_remote() {
if ! nvm_is_iojs_version "$1"; then if [ -z "$1" ] || ! nvm_is_iojs_version "$1"; then
echo "test output" echo "test_output"
echo "more test output" echo "more_test_output"
echo "pattern received: _$1_" echo "pattern_received:_$1_"
fi fi
} }
nvm_ls_remote_iojs() { nvm_ls_remote_iojs() {
if [ -z "$1" ] || nvm_is_iojs_version "$1"; then if [ -z "$1" ] || nvm_is_iojs_version "$1"; then
echo "test iojs output" echo "test_iojs_output"
echo "more iojs test output" echo "more_iojs_test_output"
echo "iojs pattern received: _$1_" echo "iojs_pattern_received:_$1_"
fi fi
} }
OUTPUT="$(nvm_remote_version foo)" OUTPUT="$(nvm_remote_version foo)"
EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_pattern received: _foo_" ] \ [ "_$OUTPUT" = "_pattern_received:_foo_" ] \
|| die "nvm_remote_version foo did not return last line only of nvm_ls_remote foo; got $OUTPUT" || die "nvm_remote_version foo did not return last line only of nvm_ls_remote foo; got $OUTPUT"
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version foo did not exit with 0, got $EXIT_CODE" [ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version foo did not exit with 0, got $EXIT_CODE"
OUTPUT="$(nvm_remote_version iojs-foo)" OUTPUT="$(nvm_remote_version iojs-foo)"
EXIT_CODE="$(nvm_remote_version iojs-foo >/dev/null 2>&1 ; echo $?)" EXIT_CODE="$(nvm_remote_version iojs-foo >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_iojs pattern received: _iojs-foo_" ] \ [ "_$OUTPUT" = "_iojs_pattern_received:_iojs-foo_" ] \
|| die "nvm_remote_version iojs-foo did not return last line only of nvm_ls_remote_iojs foo; got $OUTPUT" || die "nvm_remote_version iojs-foo did not return last line only of nvm_ls_remote_iojs foo; got $OUTPUT"
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version iojs-foo did not exit with 0, got $EXIT_CODE" [ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version iojs-foo did not exit with 0, got $EXIT_CODE"
OUTPUT="$(nvm_remote_version iojs)" OUTPUT="$(nvm_remote_version iojs)"
EXIT_CODE="$(nvm_remote_version iojs >/dev/null 2>&1 ; echo $?)" EXIT_CODE="$(nvm_remote_version iojs >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_iojs pattern received: __" ] \ [ "_$OUTPUT" = "_iojs_pattern_received:__" ] \
|| die "nvm_remote_version iojs did not return last line only of nvm_ls_remote_iojs; got $OUTPUT" || die "nvm_remote_version iojs did not return last line only of nvm_ls_remote_iojs; got $OUTPUT"
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version iojs did not exit with 0, got $EXIT_CODE" [ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version iojs did not exit with 0, got $EXIT_CODE"