Permalink
Browse files

Merge pull request #466 from creationix/nvm_ls_minor_versions

nvm_ls minor versions
  • Loading branch information...
2 parents c49cb68 + 83efa22 commit 1a9ab82e24f8daaa831da66aa22b4728dfaf2a0c @ljharb ljharb committed Jul 13, 2014
Showing with 39 additions and 6 deletions.
  1. +6 −2 nvm.sh
  2. +33 −4 test/fast/Listing versions/Running "nvm ls 0.2" should display only 0.2.x versions.
View
8 nvm.sh
@@ -153,12 +153,16 @@ nvm_ls() {
return
fi
# If it looks like an explicit version, don't do anything funny
- if [ `expr "$PATTERN" : "v[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*$"` != 0 ]; then
+ if [ `expr "$PATTERN" : "v[0-9]*\.[0-9]*\.[0-9]*$"` != 0 ]; then
if [ -d "$NVM_DIR/$PATTERN" ]; then
VERSIONS="$PATTERN"
fi
else
- VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$(nvm_format_version $PATTERN)*" -exec basename '{}' ';' \
+ PATTERN=$(nvm_format_version $PATTERN)
+ if [ `expr "$PATTERN" : "v[0-9]*\.[0-9]*$"` != 0 ]; then
+ PATTERN="$PATTERN."
+ fi
+ VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$PATTERN*" -exec basename '{}' ';' \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.'`
fi
if [ -z "$VERSIONS" ]; then
@@ -2,11 +2,40 @@
mkdir ../../../v0.1.3
mkdir ../../../v0.2.3
+mkdir ../../../v0.20.3
. ../../../nvm.sh
+die () { echo $@ ; exit 1; }
+
# The result should contain only the appropriate version numbers.
-nvm ls 0.2 | grep v0.2.3 &&
-nvm ls 0.1 | grep -v v0.2.3 &&
-nvm ls 0.1 | grep v0.1.3 &&
-nvm ls v0.2 | grep v0.2.3
+
+nvm ls 0.1 | grep 'v0.2.3' > /dev/null
+if [ $? -eq 0 ]; then
+ echo '"nvm ls 0.1" contained v0.2.3'
+fi
+
+nvm ls 0.1 | grep 'v0.20.3' > /dev/null
+if [ $? -eq 0 ]; then
+ die '"nvm ls 0.1" contained v0.20.3'
+fi
+
+nvm ls 0.1 | grep 'v0.1.3' > /dev/null
+if [ $? -ne 0 ]; then
+ die '"nvm ls 0.1" did not contain v0.1.3'
+fi
+
+nvm ls 0.2 | grep 'v0.2.3' > /dev/null
+if [ $? -ne 0 ]; then
+ die '"nvm ls 0.2" did not contain v0.2.3'
+fi
+
+nvm ls 0.2 | grep 'v0.20.3' > /dev/null
+if [ $? -eq 0 ]; then
+ die '"nvm ls 0.2" contained v0.20.3'
+fi
+
+nvm ls 0.2 | grep 'v0.2.3' > /dev/null
+if [ $? -ne 0 ]; then
+ die '"nvm ls 0.2" did not contain v0.2.3'
+fi

0 comments on commit 1a9ab82

Please sign in to comment.