mirror of
				https://github.com/nvm-sh/nvm.git
				synced 2025-10-31 10:15:53 +08:00 
			
		
		
		
	Add nvm_version_greater
				
					
				
			This commit is contained in:
		
							
								
								
									
										10
									
								
								nvm.sh
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								nvm.sh
									
									
									
									
									
								
							| @@ -95,6 +95,14 @@ nvm_rc_version() { | |||||||
|   fi |   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() { | nvm_version_dir() { | ||||||
|   local NVM_USE_NEW_DIR |   local NVM_USE_NEW_DIR | ||||||
|   NVM_USE_NEW_DIR="$1" |   NVM_USE_NEW_DIR="$1" | ||||||
| @@ -777,7 +785,7 @@ nvm() { | |||||||
|       echo "0.13.1" |       echo "0.13.1" | ||||||
|     ;; |     ;; | ||||||
|     "unload" ) |     "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 |       unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1 | ||||||
|     ;; |     ;; | ||||||
|     * ) |     * ) | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								test/fast/Unit tests/nvm_version_greater
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										10
									
								
								test/fast/Unit tests/nvm_version_greater
									
									
									
									
									
										Executable 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' | ||||||
|  |  | ||||||
		Reference in New Issue
	
	Block a user