Refactor this `nvm use` `case` statement out into an `nvm_match_version` function.

Jordan Harband 2015-06-28 18:08:38 -07:00
parent cc090f4476
commit a21b2e6962
1 changed files with 19 additions and 15 deletions

34
nvm.sh
View File

@ -1094,6 +1094,24 @@ nvm_install_node_source() {
return $? return $?
} }
nvm_match_version() {
local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
local PROVIDED_VERSION
PROVIDED_VERSION="$1"
case "_$PROVIDED_VERSION" in
"_$NVM_IOJS_PREFIX" | "_io.js")
echo "$(nvm_version $NVM_IOJS_PREFIX)"
;;
"_system")
echo "system"
;;
*)
echo "$(nvm_version "$PROVIDED_VERSION")"
;;
esac
}
nvm() { nvm() {
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
nvm help nvm help
@ -1383,22 +1401,8 @@ nvm() {
VERSION="$(nvm_version "$PROVIDED_VERSION")" VERSION="$(nvm_version "$PROVIDED_VERSION")"
fi fi
else else
local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
local NVM_NODE_PREFIX
NVM_NODE_PREFIX="$(nvm_node_prefix)"
PROVIDED_VERSION="$2" PROVIDED_VERSION="$2"
case "_$PROVIDED_VERSION" in VERSION="$(nvm_match_version "$PROVIDED_VERSION")"
"_$NVM_IOJS_PREFIX" | "_io.js")
VERSION="$(nvm_version $NVM_IOJS_PREFIX)"
;;
"_system")
VERSION="system"
;;
*)
VERSION="$(nvm_version "$PROVIDED_VERSION")"
;;
esac
fi fi
if [ -z "$VERSION" ]; then if [ -z "$VERSION" ]; then