From 110e571c34c6b23a082e0c35e85c0ee49eaf923e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 5 Sep 2014 00:10:51 -0700 Subject: [PATCH] Make `nvm ls system` work. --- nvm.sh | 13 ++++++++--- ...hould include \"system\" when appropriate" | 22 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100755 "test/fast/Listing versions/Running \"nvm ls system\" should include \"system\" when appropriate" diff --git a/nvm.sh b/nvm.sh index 008a16c..e4654ae 100644 --- a/nvm.sh +++ b/nvm.sh @@ -249,13 +249,20 @@ nvm_ls() { | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.' | \grep -e '^v'` fi fi + + if nvm_has_system_node; then + if [ -z "$PATTERN" ]; then + VERSIONS="$VERSIONS$(printf '\n%s' 'system')" + elif [ "$PATTERN" = 'system' ]; then + VERSIONS="$(printf '%s' 'system')" + fi + fi + if [ -z "$VERSIONS" ]; then echo "N/A" return 3 fi - if [ -z "$PATTERN" ] && nvm_has_system_node; then - VERSIONS="$VERSIONS$(printf '\n%s' 'system')" - fi + echo "$VERSIONS" return } diff --git "a/test/fast/Listing versions/Running \"nvm ls system\" should include \"system\" when appropriate" "b/test/fast/Listing versions/Running \"nvm ls system\" should include \"system\" when appropriate" new file mode 100755 index 0000000..3acaf3f --- /dev/null +++ "b/test/fast/Listing versions/Running \"nvm ls system\" should include \"system\" when appropriate" @@ -0,0 +1,22 @@ +#!/bin/sh + +cleanup () { unset -f nvm_has_system_node; } +die () { cleanup ; echo $@ ; exit 1; } + +. ../../../nvm.sh + +mkdir -p ../../../v0.0.1 +mkdir -p ../../../v0.0.3 +mkdir -p ../../../v0.0.9 +mkdir -p ../../../v0.3.1 +mkdir -p ../../../v0.3.3 +mkdir -p ../../../v0.3.9 + +nvm_has_system_node() { return 0; } +nvm ls system | grep system 2>&1 > /dev/null +[ $? -eq 0 ] || die '"nvm ls system" did not contain "system" when system node is present' + +nvm_has_system_node() { return 1; } +nvm ls system | grep system 2>&1 > /dev/null +[ $? -ne 0 ] || die '"nvm ls system" contained "system" when system node is not present' +