[Refactor] always shift first argument to `nvm`
parent
79270a579c
commit
206878460c
90
nvm.sh
90
nvm.sh
|
@ -1848,11 +1848,15 @@ nvm() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local COMMAND
|
||||||
|
COMMAND="${1-}"
|
||||||
|
shift
|
||||||
|
|
||||||
# initialize local variables
|
# initialize local variables
|
||||||
local VERSION
|
local VERSION
|
||||||
local ADDITIONAL_PARAMETERS
|
local ADDITIONAL_PARAMETERS
|
||||||
|
|
||||||
case $1 in
|
case $COMMAND in
|
||||||
'help' | '--help' )
|
'help' | '--help' )
|
||||||
local NVM_IOJS_PREFIX
|
local NVM_IOJS_PREFIX
|
||||||
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
|
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
|
||||||
|
@ -1953,12 +1957,10 @@ nvm() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $# -lt 2 ]; then
|
if [ $# -lt 1 ]; then
|
||||||
version_not_provided=1
|
version_not_provided=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
shift
|
|
||||||
|
|
||||||
local nobinary
|
local nobinary
|
||||||
nobinary=0
|
nobinary=0
|
||||||
local LTS
|
local LTS
|
||||||
|
@ -2141,8 +2143,6 @@ nvm() {
|
||||||
return $?
|
return $?
|
||||||
;;
|
;;
|
||||||
"uninstall" )
|
"uninstall" )
|
||||||
shift # remove "uninstall"
|
|
||||||
|
|
||||||
if [ $# -ne 1 ]; then
|
if [ $# -ne 1 ]; then
|
||||||
>&2 nvm --help
|
>&2 nvm --help
|
||||||
return 127
|
return 127
|
||||||
|
@ -2251,7 +2251,6 @@ nvm() {
|
||||||
NVM_DELETE_PREFIX=0
|
NVM_DELETE_PREFIX=0
|
||||||
local NVM_LTS
|
local NVM_LTS
|
||||||
|
|
||||||
shift # remove "use"
|
|
||||||
while [ $# -ne 0 ]
|
while [ $# -ne 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
@ -2372,7 +2371,6 @@ nvm() {
|
||||||
local has_checked_nvmrc
|
local has_checked_nvmrc
|
||||||
has_checked_nvmrc=0
|
has_checked_nvmrc=0
|
||||||
# run given version of node
|
# run given version of node
|
||||||
shift
|
|
||||||
|
|
||||||
local NVM_SILENT
|
local NVM_SILENT
|
||||||
local NVM_LTS
|
local NVM_LTS
|
||||||
|
@ -2459,8 +2457,6 @@ nvm() {
|
||||||
return $EXIT_CODE
|
return $EXIT_CODE
|
||||||
;;
|
;;
|
||||||
"exec" )
|
"exec" )
|
||||||
shift
|
|
||||||
|
|
||||||
local NVM_SILENT
|
local NVM_SILENT
|
||||||
local NVM_LTS
|
local NVM_LTS
|
||||||
while [ $# -gt 0 ]
|
while [ $# -gt 0 ]
|
||||||
|
@ -2526,10 +2522,10 @@ nvm() {
|
||||||
"ls" | "list" )
|
"ls" | "list" )
|
||||||
local NVM_LS_OUTPUT
|
local NVM_LS_OUTPUT
|
||||||
local NVM_LS_EXIT_CODE
|
local NVM_LS_EXIT_CODE
|
||||||
NVM_LS_OUTPUT=$(nvm_ls "${2-}")
|
NVM_LS_OUTPUT=$(nvm_ls "${1-}")
|
||||||
NVM_LS_EXIT_CODE=$?
|
NVM_LS_EXIT_CODE=$?
|
||||||
nvm_print_versions "$NVM_LS_OUTPUT"
|
nvm_print_versions "${NVM_LS_OUTPUT}"
|
||||||
if [ $# -eq 1 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
nvm alias
|
nvm alias
|
||||||
fi
|
fi
|
||||||
return $NVM_LS_EXIT_CODE
|
return $NVM_LS_EXIT_CODE
|
||||||
|
@ -2542,27 +2538,27 @@ nvm() {
|
||||||
NVM_NODE_PREFIX="$(nvm_node_prefix)"
|
NVM_NODE_PREFIX="$(nvm_node_prefix)"
|
||||||
local PATTERN
|
local PATTERN
|
||||||
local NVM_FLAVOR
|
local NVM_FLAVOR
|
||||||
while [ $# -gt 1 ]
|
while [ $# -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$2" in
|
case "${1-}" in
|
||||||
--lts)
|
--lts)
|
||||||
LTS='*'
|
LTS='*'
|
||||||
;;
|
;;
|
||||||
--lts=*)
|
--lts=*)
|
||||||
LTS="${2##--lts=}"
|
LTS="${1##--lts=}"
|
||||||
NVM_FLAVOR="${NVM_NODE_PREFIX}"
|
NVM_FLAVOR="${NVM_NODE_PREFIX}"
|
||||||
;;
|
;;
|
||||||
--*)
|
--*)
|
||||||
nvm_err "Unsupported option \"$2\"."
|
nvm_err "Unsupported option \"${1}\"."
|
||||||
return 55;
|
return 55;
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [ -z "$PATTERN" ]; then
|
if [ -z "${PATTERN}" ]; then
|
||||||
PATTERN="${2-}"
|
PATTERN="${1-}"
|
||||||
if [ -z "$NVM_FLAVOR" ]; then
|
if [ -z "${NVM_FLAVOR}" ]; then
|
||||||
case "_$PATTERN" in
|
case "_${PATTERN}" in
|
||||||
"_$NVM_IOJS_PREFIX" | "_$NVM_NODE_PREFIX")
|
"_${NVM_IOJS_PREFIX}" | "_${NVM_NODE_PREFIX}")
|
||||||
NVM_FLAVOR="$PATTERN"
|
NVM_FLAVOR="${PATTERN}"
|
||||||
PATTERN=""
|
PATTERN=""
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -2614,19 +2610,19 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')"
|
||||||
;;
|
;;
|
||||||
"which" )
|
"which" )
|
||||||
local provided_version
|
local provided_version
|
||||||
provided_version="$2"
|
provided_version="${1-}"
|
||||||
if [ $# -eq 1 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
nvm_rc_version
|
nvm_rc_version
|
||||||
if [ -n "$NVM_RC_VERSION" ]; then
|
if [ -n "${NVM_RC_VERSION}" ]; then
|
||||||
provided_version="$NVM_RC_VERSION"
|
provided_version="${NVM_RC_VERSION}"
|
||||||
VERSION=$(nvm_version "$NVM_RC_VERSION" || return 0)
|
VERSION=$(nvm_version "${NVM_RC_VERSION}" || return 0)
|
||||||
fi
|
fi
|
||||||
elif [ "_$2" != '_system' ]; then
|
elif [ "_${1}" != '_system' ]; then
|
||||||
VERSION="$(nvm_version "$provided_version" || return 0)"
|
VERSION="$(nvm_version "${provided_version}" || return 0)"
|
||||||
else
|
else
|
||||||
VERSION="$2"
|
VERSION="${1-}"
|
||||||
fi
|
fi
|
||||||
if [ -z "$VERSION" ]; then
|
if [ -z "${VERSION}" ]; then
|
||||||
>&2 nvm --help
|
>&2 nvm --help
|
||||||
return 127
|
return 127
|
||||||
fi
|
fi
|
||||||
|
@ -2660,8 +2656,6 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')"
|
||||||
nvm_echo "$NVM_VERSION_DIR/bin/node"
|
nvm_echo "$NVM_VERSION_DIR/bin/node"
|
||||||
;;
|
;;
|
||||||
"alias" )
|
"alias" )
|
||||||
shift
|
|
||||||
|
|
||||||
local NVM_ALIAS_DIR
|
local NVM_ALIAS_DIR
|
||||||
NVM_ALIAS_DIR="$(nvm_alias_path)"
|
NVM_ALIAS_DIR="$(nvm_alias_path)"
|
||||||
local NVM_CURRENT
|
local NVM_CURRENT
|
||||||
|
@ -2721,28 +2715,28 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')"
|
||||||
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"
|
command mkdir -p "$NVM_ALIAS_DIR"
|
||||||
if [ $# -ne 2 ]; then
|
if [ $# -ne 1 ]; then
|
||||||
>&2 nvm --help
|
>&2 nvm --help
|
||||||
return 127
|
return 127
|
||||||
fi
|
fi
|
||||||
if [ "${2#*\/}" != "${2-}" ]; then
|
if [ "${1#*\/}" != "${1-}" ]; then
|
||||||
nvm_err 'Aliases in subdirectories are not supported.'
|
nvm_err 'Aliases in subdirectories are not supported.'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
[ ! -f "$NVM_ALIAS_DIR/$2" ] && nvm_err "Alias $2 doesn't exist!" && return
|
[ ! -f "$NVM_ALIAS_DIR/${1-}" ] && nvm_err "Alias ${1-} doesn't exist!" && return
|
||||||
local NVM_ALIAS_ORIGINAL
|
local NVM_ALIAS_ORIGINAL
|
||||||
NVM_ALIAS_ORIGINAL="$(nvm_alias "$2")"
|
NVM_ALIAS_ORIGINAL="$(nvm_alias "${1}")"
|
||||||
command rm -f "$NVM_ALIAS_DIR/$2"
|
command rm -f "$NVM_ALIAS_DIR/${1}"
|
||||||
nvm_echo "Deleted alias $2 - restore it with \`nvm alias \"$2\" \"$NVM_ALIAS_ORIGINAL\"\`"
|
nvm_echo "Deleted alias ${1} - restore it with \`nvm alias \"${1}\" \"$NVM_ALIAS_ORIGINAL\"\`"
|
||||||
;;
|
;;
|
||||||
"reinstall-packages" | "copy-packages" )
|
"reinstall-packages" | "copy-packages" )
|
||||||
if [ $# -ne 2 ]; then
|
if [ $# -ne 1 ]; then
|
||||||
>&2 nvm --help
|
>&2 nvm --help
|
||||||
return 127
|
return 127
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local PROVIDED_VERSION
|
local PROVIDED_VERSION
|
||||||
PROVIDED_VERSION="$2"
|
PROVIDED_VERSION="${1-}"
|
||||||
|
|
||||||
if [ "$PROVIDED_VERSION" = "$(nvm_ls_current)" ] || [ "$(nvm_version "$PROVIDED_VERSION" || return 0)" = "$(nvm_ls_current)" ]; then
|
if [ "$PROVIDED_VERSION" = "$(nvm_ls_current)" ] || [ "$(nvm_version "$PROVIDED_VERSION" || return 0)" = "$(nvm_ls_current)" ]; then
|
||||||
nvm_err 'Can not reinstall packages from the current version of node.'
|
nvm_err 'Can not reinstall packages from the current version of node.'
|
||||||
|
@ -2786,26 +2780,26 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')"
|
||||||
nvm_echo 'Cache cleared.'
|
nvm_echo 'Cache cleared.'
|
||||||
;;
|
;;
|
||||||
"version" )
|
"version" )
|
||||||
nvm_version "$2"
|
nvm_version "${1}"
|
||||||
;;
|
;;
|
||||||
"version-remote" )
|
"version-remote" )
|
||||||
local NVM_LTS
|
local NVM_LTS
|
||||||
local PATTERN
|
local PATTERN
|
||||||
while [ $# -gt 1 ]
|
while [ $# -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$2" in
|
case "${1-}" in
|
||||||
--lts)
|
--lts)
|
||||||
NVM_LTS='*'
|
NVM_LTS='*'
|
||||||
;;
|
;;
|
||||||
--lts=*)
|
--lts=*)
|
||||||
NVM_LTS="${2##--lts=}"
|
NVM_LTS="${1##--lts=}"
|
||||||
;;
|
;;
|
||||||
--*)
|
--*)
|
||||||
nvm_err "Unsupported option \"$2\"."
|
nvm_err "Unsupported option \"${1}\"."
|
||||||
return 55;
|
return 55;
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
PATTERN="${PATTERN:-$2}"
|
PATTERN="${PATTERN:-${1}}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
|
|
Loading…
Reference in New Issue