Add `nvm_version_greater`

master
Jordan Harband 2014-08-20 00:01:06 -07:00
parent a2da9abd6d
commit 8fe677a644
2 changed files with 19 additions and 1 deletions

10
nvm.sh
View File

@ -95,6 +95,14 @@ nvm_rc_version() {
fi
}
nvm_version_greater() {
local LHS
LHS=$(echo "$1" | awk -F. '{for (i=1;i<=NF;++i) printf "%010d",$i}')
local RHS
RHS=$(echo "$2" | awk -F. '{for (i=1;i<=NF;++i) printf "%010d",$i}')
[ $LHS \> $RHS ];
}
nvm_version_dir() {
local NVM_USE_NEW_DIR
NVM_USE_NEW_DIR="$1"
@ -777,7 +785,7 @@ nvm() {
echo "0.13.1"
;;
"unload" )
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version > /dev/null 2>&1
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version nvm_version_greater > /dev/null 2>&1
unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1
;;
* )

View File

@ -0,0 +1,10 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm_version_greater 0.10.0 0.2.12 || die '"nvm_version_greater 0.10.0 0.2.12" did not return true'
! nvm_version_greater 0.10.0 0.20.12 || die '"nvm_version_greater 0.10.0 0.20.12" returned true'
! nvm_version_greater 0.10.0 0.10.0 || die '"nvm_version_greater" returned false for the same two versions'