Adding nvm_resolve_alias
parent
08aa09e664
commit
7a339bdd3c
35
nvm.sh
35
nvm.sh
|
@ -270,6 +270,32 @@ nvm_ls_current() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvm_resolve_alias() {
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local PATTERN
|
||||||
|
PATTERN="$1"
|
||||||
|
|
||||||
|
if [ -f "$NVM_DIR/alias/$PATTERN" ]; then
|
||||||
|
nvm_version "$(nvm_alias "$PATTERN" 2> /dev/null)"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then
|
||||||
|
local IMPLICIT
|
||||||
|
IMPLICIT="$(nvm_print_implicit_alias local "$PATTERN" 2> /dev/null)"
|
||||||
|
if [ -n "$IMPLICIT" ]; then
|
||||||
|
nvm_version "$IMPLICIT"
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
|
||||||
nvm_ls() {
|
nvm_ls() {
|
||||||
local PATTERN
|
local PATTERN
|
||||||
PATTERN=$1
|
PATTERN=$1
|
||||||
|
@ -280,10 +306,10 @@ nvm_ls() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$NVM_DIR/alias/$PATTERN" ]; then
|
if nvm_resolve_alias "$PATTERN"; then
|
||||||
nvm_version "$(nvm_alias "$PATTERN" 2> /dev/null)"
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If it looks like an explicit version, don't do anything funny
|
# If it looks like an explicit version, don't do anything funny
|
||||||
PATTERN=$(nvm_ensure_version_prefix $PATTERN)
|
PATTERN=$(nvm_ensure_version_prefix $PATTERN)
|
||||||
if [ "_$(echo "$PATTERN" | cut -c1-1)" = "_v" ] && [ "_$(nvm_num_version_groups "$PATTERN")" = "_3" ]; then
|
if [ "_$(echo "$PATTERN" | cut -c1-1)" = "_v" ] && [ "_$(nvm_num_version_groups "$PATTERN")" = "_3" ]; then
|
||||||
|
@ -292,11 +318,6 @@ nvm_ls() {
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ "_$PATTERN" != "_system" ]; then
|
if [ "_$PATTERN" != "_system" ]; then
|
||||||
if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then
|
|
||||||
nvm_ls "$(nvm_print_implicit_alias local "$PATTERN" 2> /dev/null)"
|
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
local NUM_VERSION_GROUPS
|
local NUM_VERSION_GROUPS
|
||||||
NUM_VERSION_GROUPS="$(nvm_num_version_groups "$PATTERN")"
|
NUM_VERSION_GROUPS="$(nvm_num_version_groups "$PATTERN")"
|
||||||
if [ "_$NUM_VERSION_GROUPS" = "_2" ] || [ "_$NUM_VERSION_GROUPS" = "_1" ]; then
|
if [ "_$NUM_VERSION_GROUPS" = "_2" ] || [ "_$NUM_VERSION_GROUPS" = "_1" ]; then
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo $@ ; exit 1; }
|
||||||
|
|
||||||
|
. ../../../nvm.sh
|
||||||
|
|
||||||
|
EXIT_CODE=$(nvm_resolve_alias ; echo $?)
|
||||||
|
[ $EXIT_CODE = "1" ] || die "nvm_resolve_alias without an argument did not return 1; got $EXIT_CODE"
|
||||||
|
|
||||||
|
for i in $(seq 1 10)
|
||||||
|
do
|
||||||
|
STABLE_ALIAS="$(nvm_resolve_alias test-stable-$i)"
|
||||||
|
[ "_$STABLE_ALIAS" = "_v0.0.$i" ] \
|
||||||
|
|| die "'nvm_resolve_alias test-stable-$i' was not v0.0.$i; got $STABLE_ALIAS"
|
||||||
|
UNSTABLE_ALIAS="$(nvm_resolve_alias test-unstable-$i)"
|
||||||
|
[ "_$UNSTABLE_ALIAS" = "_v0.1.$i" ] \
|
||||||
|
|| die "'nvm_resolve_alias test-unstable-$i' was not v0.1.$i; got $UNSTABLE_ALIAS"
|
||||||
|
done
|
||||||
|
|
||||||
|
EXIT_CODE=$(nvm_resolve_alias nonexistent ; echo $?)
|
||||||
|
[ $EXIT_CODE = "2" ] || die "'nvm_resolve_alias nonexistent' did not return 2; got $EXIT_CODE"
|
||||||
|
|
||||||
|
STABLE="$(nvm_resolve_alias stable)"
|
||||||
|
[ "_$STABLE" = "_v0.0.10" ] || die "'nvm_resolve_alias stable' was not v0.0.10; got $STABLE"
|
||||||
|
|
||||||
|
UNSTABLE="$(nvm_resolve_alias unstable)"
|
||||||
|
[ "_$UNSTABLE" = "_v0.1.10" ] || die "'nvm_resolve_alias unstable' was not v0.1.10; got $UNSTABLE"
|
||||||
|
|
Loading…
Reference in New Issue