Separate `nvm_resolve_alias`'s `nvm_version` behavior into `nvm_resolve_local_alias`.
parent
cd481ff548
commit
7d22e0c458
28
nvm.sh
28
nvm.sh
|
@ -425,7 +425,7 @@ nvm_resolve_alias() {
|
|||
if [ "_$ALIAS" = "_∞" ]; then
|
||||
echo "$ALIAS"
|
||||
else
|
||||
nvm_version "$ALIAS"
|
||||
nvm_ensure_version_prefix "$ALIAS"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
@ -434,15 +434,33 @@ nvm_resolve_alias() {
|
|||
local IMPLICIT
|
||||
IMPLICIT="$(nvm_print_implicit_alias local "$PATTERN" 2> /dev/null)"
|
||||
if [ -n "$IMPLICIT" ]; then
|
||||
nvm_version "$IMPLICIT"
|
||||
return $?
|
||||
nvm_ensure_version_prefix "$IMPLICIT"
|
||||
fi
|
||||
return 3
|
||||
fi
|
||||
|
||||
return 2
|
||||
}
|
||||
|
||||
nvm_resolve_local_alias() {
|
||||
if [ -z "$1" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
local VERSION
|
||||
local EXIT_CODE
|
||||
VERSION="$(nvm_resolve_alias "$1")"
|
||||
EXIT_CODE=$?
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "N/A"
|
||||
return $EXIT_CODE
|
||||
fi
|
||||
if [ "_$VERSION" != "_∞" ]; then
|
||||
nvm_version "$VERSION"
|
||||
else
|
||||
echo "$VERSION"
|
||||
fi
|
||||
}
|
||||
|
||||
nvm_iojs_prefix() {
|
||||
echo "iojs"
|
||||
}
|
||||
|
@ -494,7 +512,7 @@ nvm_ls() {
|
|||
PATTERN="$PATTERN-"
|
||||
;;
|
||||
*)
|
||||
if nvm_resolve_alias "$PATTERN"; then
|
||||
if nvm_resolve_local_alias "$PATTERN"; then
|
||||
return
|
||||
fi
|
||||
PATTERN=$(nvm_ensure_version_prefix $PATTERN)
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; exit 1; }
|
||||
|
||||
. ../../../../nvm.sh
|
||||
|
||||
ALIAS="$(nvm_resolve_local_alias loopback)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias loopback was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias loopback)"
|
||||
EXPECTED_OUTPUT="loopback -> loopback (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias loopback was not $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
ALIAS="$(nvm_resolve_local_alias one)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias one was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias one)"
|
||||
EXPECTED_OUTPUT="one -> two (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias one was not $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
ALIAS="$(nvm_resolve_local_alias two)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias two was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias two)"
|
||||
EXPECTED_OUTPUT="two -> three (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias two was not $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
ALIAS="$(nvm_resolve_local_alias three)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias three was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias three)"
|
||||
EXPECTED_OUTPUT="three -> one (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias three was not $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
ALIAS="$(nvm_resolve_local_alias four)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias four was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias four)"
|
||||
EXPECTED_OUTPUT="four -> two (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias four was not $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
|
@ -21,13 +21,13 @@ 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"
|
||||
[ "_$STABLE" = "_v0.0" ] || die "'nvm_resolve_alias stable' was not v0.0; got $STABLE"
|
||||
|
||||
NODE="$(nvm_resolve_alias node)"
|
||||
[ "_$NODE" = "_v0.0.10" ] || die "'nvm_resolve_alias node' was not v0.0.10; got $NODE"
|
||||
[ "_$NODE" = "_stable" ] || die "'nvm_resolve_alias node' was not stable; got $NODE"
|
||||
|
||||
UNSTABLE="$(nvm_resolve_alias unstable)"
|
||||
[ "_$UNSTABLE" = "_v0.1.10" ] || die "'nvm_resolve_alias unstable' was not v0.1.10; got $UNSTABLE"
|
||||
[ "_$UNSTABLE" = "_v0.1" ] || die "'nvm_resolve_alias unstable' was not v0.1; got $UNSTABLE"
|
||||
|
||||
IOJS="$(nvm_resolve_alias iojs)"
|
||||
[ "_$IOJS" = "_iojs-v0.2.10" ] || die "'nvm_resolve_alias iojs' was not iojs-v0.2.10; got $IOJS"
|
||||
[ "_$IOJS" = "_iojs-v0.2" ] || die "'nvm_resolve_alias iojs' was not iojs-v0.2; got $IOJS"
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; exit 1; }
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
EXIT_CODE=$(nvm_resolve_local_alias ; echo $?)
|
||||
[ "_$EXIT_CODE" = "_1" ] || die "nvm_resolve_local_alias without an argument did not return 1; got $EXIT_CODE"
|
||||
|
||||
for i in $(seq 1 10)
|
||||
do
|
||||
STABLE_ALIAS="$(nvm_resolve_local_alias test-stable-$i)"
|
||||
[ "_$STABLE_ALIAS" = "_v0.0.$i" ] \
|
||||
|| die "'nvm_resolve_local_alias test-stable-$i' was not v0.0.$i; got $STABLE_ALIAS"
|
||||
UNSTABLE_ALIAS="$(nvm_resolve_local_alias test-unstable-$i)"
|
||||
[ "_$UNSTABLE_ALIAS" = "_v0.1.$i" ] \
|
||||
|| die "'nvm_resolve_local_alias test-unstable-$i' was not v0.1.$i; got $UNSTABLE_ALIAS"
|
||||
done
|
||||
|
||||
OUTPUT="$(nvm_resolve_local_alias nonexistent)"
|
||||
EXIT_CODE=$(nvm_resolve_local_alias nonexistent > /dev/null 2>&1 ; echo $?)
|
||||
[ "_$EXIT_CODE" = "_2" ] || die "'nvm_resolve_local_alias nonexistent' did not return 2; got $EXIT_CODE"
|
||||
[ "_$OUTPUT" = "_N/A" ] || die "'nvm_resolve_local_alias nonexistent' did not output N/A; got $OUTPUT"
|
||||
|
||||
STABLE="$(nvm_resolve_local_alias stable)"
|
||||
[ "_$STABLE" = "_v0.0.10" ] || die "'nvm_resolve_local_alias stable' was not v0.0.10; got $STABLE"
|
||||
|
||||
NODE="$(nvm_resolve_local_alias node)"
|
||||
[ "_$NODE" = "_v0.0.10" ] || die "'nvm_resolve_local_alias node' was not v0.0.10; got $NODE"
|
||||
|
||||
UNSTABLE="$(nvm_resolve_local_alias unstable)"
|
||||
[ "_$UNSTABLE" = "_v0.1.10" ] || die "'nvm_resolve_local_alias unstable' was not v0.1.10; got $UNSTABLE"
|
||||
|
||||
IOJS="$(nvm_resolve_local_alias iojs)"
|
||||
[ "_$IOJS" = "_iojs-v0.2.10" ] || die "'nvm_resolve_local_alias iojs' was not iojs-v0.2.10; got $IOJS"
|
Loading…
Reference in New Issue