From c918e570b63894f05128d311ee261c9cad2691f5 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 29 Sep 2014 00:09:48 -0700 Subject: [PATCH] Add support for `nvm ls stable` and `nvm ls unstable` --- nvm.sh | 5 ++++ ...uld return the appropriate implicit alias" | 25 +++++++++++++++++++ test/fast/Listing versions/teardown | 2 ++ 3 files changed, 32 insertions(+) create mode 100755 "test/fast/Listing versions/Running \"nvm ls stable\" and \"nvm ls unstable\" should return the appropriate implicit alias" diff --git a/nvm.sh b/nvm.sh index e3c20f1..85c850e 100644 --- a/nvm.sh +++ b/nvm.sh @@ -274,6 +274,11 @@ nvm_ls() { fi else if [ "_$PATTERN" != "_system" ]; then + if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then + nvm_ls "$(nvm_print_implicit_alias local "$PATTERN" 2> /dev/null)" + return $? + fi + local NUM_VERSION_GROUPS NUM_VERSION_GROUPS="$(nvm_num_version_groups "$PATTERN")" if [ "_$NUM_VERSION_GROUPS" = "_2" ] || [ "_$NUM_VERSION_GROUPS" = "_1" ]; then diff --git "a/test/fast/Listing versions/Running \"nvm ls stable\" and \"nvm ls unstable\" should return the appropriate implicit alias" "b/test/fast/Listing versions/Running \"nvm ls stable\" and \"nvm ls unstable\" should return the appropriate implicit alias" new file mode 100755 index 0000000..f744ffe --- /dev/null +++ "b/test/fast/Listing versions/Running \"nvm ls stable\" and \"nvm ls unstable\" should return the appropriate implicit alias" @@ -0,0 +1,25 @@ + #!/bin/sh + +. ../../../nvm.sh + +die () { echo $@ ; exit 1; } + +EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" +STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" + +EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" +UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" + +nvm ls stable | \grep "$STABLE_VERSION" >/dev/null \ + || die "expected 'nvm ls stable' to give $STABLE_VERSION, got $(nvm ls stable)" + +nvm ls unstable | \grep "$UNSTABLE_VERSION" >/dev/null \ + || die "expected 'nvm ls unstable' to give $UNSTABLE_VERSION, got $(nvm ls unstable)" + +mkdir ../../../v0.1.2 +nvm alias stable 0.1 + +nvm ls stable | \grep v0.1.2 >/dev/null \ + && nvm ls stable | \grep -v "$STABLE_VERSION" >/dev/null \ + || die "'nvm ls stable' did not contain an explicit 'stable' alias" + diff --git a/test/fast/Listing versions/teardown b/test/fast/Listing versions/teardown index 3c5f013..b1c31a5 100755 --- a/test/fast/Listing versions/teardown +++ b/test/fast/Listing versions/teardown @@ -11,4 +11,6 @@ rmdir ../../../v0.3.3 >/dev/null 2>&1 rmdir ../../../v0.3.9 >/dev/null 2>&1 rmdir ../../../versions >/dev/null 2>&1 unalias nvm_has_system_node >/dev/null 2>&1 +rm -f ../../../alias/stable >/dev/null 2>&1 +rm -f ../../../alias/unstable >/dev/null 2>&1