[Docs] `unalias`: add more specific error message for builtin aliases

Lucas Kellner 2019-01-23 16:39:57 -08:00 committed by Jordan Harband
parent cc0750eb5d
commit 02997b0753
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
2 changed files with 37 additions and 0 deletions

12
nvm.sh
View File

@ -3335,6 +3335,18 @@ nvm() {
nvm_err 'Aliases in subdirectories are not supported.'
return 1
fi
local NVM_IOJS_PREFIX
local NVM_NODE_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
NVM_NODE_PREFIX="$(nvm_node_prefix)"
case "$1" in
"stable" | "unstable" | "${NVM_IOJS_PREFIX}" | "${NVM_NODE_PREFIX}" | "system")
nvm_err "${1-} is a default (built-in) alias and cannot be deleted."
return 1
;;
esac
[ ! -f "${NVM_ALIAS_DIR}/${1-}" ] && nvm_err "Alias ${1-} doesn't exist!" && return
local NVM_ALIAS_ORIGINAL
NVM_ALIAS_ORIGINAL="$(nvm_alias "${1}")"

View File

@ -0,0 +1,25 @@
#!/bin/sh
\. ../../../nvm.sh
die () { echo "$@" ; exit 1; }
OUTPUT="$(nvm unalias node 2>&1)"
EXPECTED_OUTPUT="node is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
OUTPUT="$(nvm unalias stable 2>&1)"
EXPECTED_OUTPUT="stable is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
OUTPUT="$(nvm unalias unstable 2>&1)"
EXPECTED_OUTPUT="unstable is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
OUTPUT="$(nvm unalias iojs 2>&1)"
EXPECTED_OUTPUT="iojs is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
OUTPUT="$(nvm unalias system 2>&1)"
EXPECTED_OUTPUT="system is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"