`nvm alias`: factor out alias creation to `nvm_make_alias`
parent
2d50606a78
commit
1c3f8da6c3
24
nvm.sh
24
nvm.sh
|
@ -464,6 +464,22 @@ nvm_print_default_alias() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvm_make_alias() {
|
||||||
|
local ALIAS
|
||||||
|
ALIAS="${1-}"
|
||||||
|
if [ -z "$ALIAS" ]; then
|
||||||
|
>&2 echo "an alias name is required"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
local VERSION
|
||||||
|
VERSION="${2-}"
|
||||||
|
if [ -z "$VERSION" ]; then
|
||||||
|
>&2 echo "an alias target version is required"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
echo "$VERSION" | tee "$(nvm_alias_path)/${ALIAS}" >/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
nvm_alias() {
|
nvm_alias() {
|
||||||
local ALIAS
|
local ALIAS
|
||||||
ALIAS="${1-}"
|
ALIAS="${1-}"
|
||||||
|
@ -2356,11 +2372,11 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d'
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "! WARNING: Version '${3-}' does not exist." >&2
|
echo "! WARNING: Version '${3-}' does not exist." >&2
|
||||||
fi
|
fi
|
||||||
echo "$3" | tee "$NVM_ALIAS_DIR/${2-}" >/dev/null
|
nvm_make_alias "${2-}" "${3-}"
|
||||||
if [ ! "_$3" = "_$VERSION" ]; then
|
if [ "_$3" = "_$VERSION" ]; then
|
||||||
echo "${2-} -> ${3-} (-> $VERSION)"
|
|
||||||
else
|
|
||||||
echo "${2-} -> ${3-}"
|
echo "${2-} -> ${3-}"
|
||||||
|
else
|
||||||
|
echo "${2-} -> ${3-} (-> $VERSION)"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"unalias" )
|
"unalias" )
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo $@ ; exit 1; }
|
||||||
|
|
||||||
|
. ../../../nvm.sh
|
||||||
|
|
||||||
|
OUTPUT="$(nvm_make_alias 2>&1)"
|
||||||
|
EXIT_CODE="$(nvm_make_alias >/dev/null 2>&1 ; echo $?)"
|
||||||
|
EXPECTED_OUTPUT='an alias name is required'
|
||||||
|
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "\`nvm_make_alias\` did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||||
|
[ "$EXIT_CODE" -eq 1 ] || die "\`nvm_make_alias\` did not exit with 1, got '$EXIT_CODE'"
|
||||||
|
|
||||||
|
OUTPUT="$(nvm_make_alias foo 2>&1)"
|
||||||
|
EXIT_CODE="$(nvm_make_alias foo >/dev/null 2>&1 ; echo $?)"
|
||||||
|
EXPECTED_OUTPUT='an alias target version is required'
|
||||||
|
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "\`nvm_make_alias foo\` did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||||
|
[ "$EXIT_CODE" -eq 2 ] || die "\`nvm_make_alias foo\` did not exit with 2, got '$EXIT_CODE'"
|
Loading…
Reference in New Issue