[Refactor] `nvm alias`: use named vars instead of positional args.
parent
a3bc4d3e62
commit
21b8f556b2
31
nvm.sh
31
nvm.sh
|
@ -2630,6 +2630,11 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')"
|
||||||
"alias" )
|
"alias" )
|
||||||
shift
|
shift
|
||||||
|
|
||||||
|
local ALIAS
|
||||||
|
ALIAS="${1-}"
|
||||||
|
local TARGET
|
||||||
|
TARGET="${2-}"
|
||||||
|
|
||||||
local NVM_ALIAS_DIR
|
local NVM_ALIAS_DIR
|
||||||
NVM_ALIAS_DIR="$(nvm_alias_path)"
|
NVM_ALIAS_DIR="$(nvm_alias_path)"
|
||||||
command mkdir -p "$NVM_ALIAS_DIR/lts"
|
command mkdir -p "$NVM_ALIAS_DIR/lts"
|
||||||
|
@ -2637,19 +2642,19 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')"
|
||||||
NVM_CURRENT="$(nvm_ls_current)"
|
NVM_CURRENT="$(nvm_ls_current)"
|
||||||
if [ $# -le 1 ]; then
|
if [ $# -le 1 ]; then
|
||||||
local ALIAS_PATH
|
local ALIAS_PATH
|
||||||
for ALIAS_PATH in "$NVM_ALIAS_DIR/${1-}"*; do
|
for ALIAS_PATH in "$NVM_ALIAS_DIR/${ALIAS}"*; do
|
||||||
NVM_CURRENT="${NVM_CURRENT}" nvm_print_alias_path "$NVM_ALIAS_DIR" "$ALIAS_PATH"
|
NVM_CURRENT="${NVM_CURRENT}" nvm_print_alias_path "$NVM_ALIAS_DIR" "$ALIAS_PATH"
|
||||||
done
|
done
|
||||||
|
|
||||||
local ALIAS
|
local ALIAS_NAME
|
||||||
for ALIAS in "$(nvm_node_prefix)" "stable" "unstable" "$(nvm_iojs_prefix)"; do
|
for ALIAS_NAME in "$(nvm_node_prefix)" "stable" "unstable" "$(nvm_iojs_prefix)"; do
|
||||||
if [ ! -f "$NVM_ALIAS_DIR/$ALIAS" ] && ([ $# -lt 1 ] || [ "~$ALIAS" = "~${1-}" ]); then
|
if [ ! -f "${NVM_ALIAS_DIR}/${ALIAS}" ] && ([ $# -lt 1 ] || [ "~${ALIAS_NAME}" = "~${ALIAS}" ]); then
|
||||||
NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "$ALIAS"
|
NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "$ALIAS_NAME"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
local LTS_ALIAS
|
local LTS_ALIAS
|
||||||
for ALIAS_PATH in "$NVM_ALIAS_DIR/lts/${1-}"*; do
|
for ALIAS_PATH in "$NVM_ALIAS_DIR/lts/${ALIAS}"*; do
|
||||||
LTS_ALIAS="$(NVM_LTS=true nvm_print_alias_path "$NVM_ALIAS_DIR" "$ALIAS_PATH")"
|
LTS_ALIAS="$(NVM_LTS=true nvm_print_alias_path "$NVM_ALIAS_DIR" "$ALIAS_PATH")"
|
||||||
if [ -n "$LTS_ALIAS" ]; then
|
if [ -n "$LTS_ALIAS" ]; then
|
||||||
nvm_echo "${LTS_ALIAS-}"
|
nvm_echo "${LTS_ALIAS-}"
|
||||||
|
@ -2657,20 +2662,20 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')"
|
||||||
done
|
done
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
if [ -z "${2-}" ]; then
|
if [ -z "${TARGET}" ]; then
|
||||||
nvm unalias "${1-}"
|
nvm unalias "${ALIAS}"
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
if [ "${1#*\/}" != "${1-}" ]; then
|
if [ "${ALIAS#*\/}" != "${ALIAS}" ]; then
|
||||||
nvm_err 'Aliases in subdirectories are not supported.'
|
nvm_err 'Aliases in subdirectories are not supported.'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
VERSION="$(nvm_version "${2-}" || return 0)"
|
VERSION="$(nvm_version "${TARGET}" || return 0)"
|
||||||
if [ "$VERSION" = 'N/A' ]; then
|
if [ "$VERSION" = 'N/A' ]; then
|
||||||
nvm_err "! WARNING: Version '${2-}' does not exist."
|
nvm_err "! WARNING: Version '${TARGET}' does not exist."
|
||||||
fi
|
fi
|
||||||
nvm_make_alias "${1-}" "${2-}"
|
nvm_make_alias "${ALIAS}" "${TARGET}"
|
||||||
NVM_CURRENT="${NVM_CURRENT-}" DEFAULT=false nvm_print_formatted_alias "${1-}" "${2-}" "$VERSION"
|
NVM_CURRENT="${NVM_CURRENT-}" DEFAULT=false nvm_print_formatted_alias "${ALIAS}" "${TARGET}" "$VERSION"
|
||||||
;;
|
;;
|
||||||
"unalias" )
|
"unalias" )
|
||||||
local NVM_ALIAS_DIR
|
local NVM_ALIAS_DIR
|
||||||
|
|
Loading…
Reference in New Issue