[Fix] nvm: treat a bare --only like an empty --only=
Every command that accepts `--only=<categories>` only recognized it with an `=`, so a bare `--only` got whatever an unknown argument gets, and no command said what was wrong with it. `nvm ls`, `nvm ls-remote`, `nvm exec`, `nvm alias`, and `nvm version-remote` rejected it as an unsupported option; `nvm uninstall` and `nvm reinstall-packages` printed their usage; `nvm use`, `nvm which`, `nvm run`, and `nvm version` took it, or the version after it, as the version to look for; and `nvm install --only 20` printed grep's usage, while `nvm install 20 --only` ignored it. A bare `--only` is now parsed as `--only=` with an empty value, so every command gives the same error for both: `--only` needs a comma-separated list of categories. Aliases already reject such a value when they are created, so stored alias targets need no change.
This commit is contained in:
2 files changed
+105
-27
No files matched your search
@@ -5067,8 +5067,9 @@ nvm() {
|
||||
LTS="${1##--lts=}"
|
||||
shift
|
||||
;;
|
||||
--only=*)
|
||||
NVM_ONLY_FLAG="${1#--only=}"
|
||||
--only | --only=*)
|
||||
NVM_ONLY_FLAG="${1#--only}"
|
||||
NVM_ONLY_FLAG="${NVM_ONLY_FLAG#=}"
|
||||
NVM_ONLY_FLAG_COUNT=$((NVM_ONLY_FLAG_COUNT + 1))
|
||||
shift
|
||||
;;
|
||||
@@ -5142,8 +5143,9 @@ nvm() {
|
||||
local NVM_INSTALL_ARG
|
||||
for NVM_INSTALL_ARG in "$@"; do
|
||||
case "${NVM_INSTALL_ARG}" in
|
||||
--only=*)
|
||||
NVM_ONLY_FLAG="${NVM_INSTALL_ARG#--only=}"
|
||||
--only | --only=*)
|
||||
NVM_ONLY_FLAG="${NVM_INSTALL_ARG#--only}"
|
||||
NVM_ONLY_FLAG="${NVM_ONLY_FLAG#=}"
|
||||
NVM_ONLY_FLAG_COUNT=$((NVM_ONLY_FLAG_COUNT + 1))
|
||||
;;
|
||||
---*)
|
||||
@@ -5373,7 +5375,7 @@ nvm() {
|
||||
fi
|
||||
NVM_WRITE_TO_NVMRC=1
|
||||
;;
|
||||
--only=*) ;;
|
||||
--only | --only=*) ;;
|
||||
*)
|
||||
ADDITIONAL_PARAMETERS="${ADDITIONAL_PARAMETERS} $1"
|
||||
;;
|
||||
@@ -5576,8 +5578,9 @@ nvm() {
|
||||
NVM_UNINSTALL_ARGS=0
|
||||
while [ $# -ne 0 ]; do
|
||||
case "${1}" in
|
||||
--only=*)
|
||||
NVM_ONLY_FLAG="${1#--only=}"
|
||||
--only | --only=*)
|
||||
NVM_ONLY_FLAG="${1#--only}"
|
||||
NVM_ONLY_FLAG="${NVM_ONLY_FLAG#=}"
|
||||
NVM_ONLY_FLAG_COUNT=$((NVM_ONLY_FLAG_COUNT + 1))
|
||||
;;
|
||||
*)
|
||||
@@ -5790,8 +5793,9 @@ nvm() {
|
||||
;;
|
||||
--lts) NVM_LTS='*' ;;
|
||||
--lts=*) NVM_LTS="${1##--lts=}" ;;
|
||||
--only=*)
|
||||
NVM_ONLY_FLAG="${1#--only=}"
|
||||
--only | --only=*)
|
||||
NVM_ONLY_FLAG="${1#--only}"
|
||||
NVM_ONLY_FLAG="${NVM_ONLY_FLAG#=}"
|
||||
NVM_ONLY_FLAG_COUNT=$((NVM_ONLY_FLAG_COUNT + 1))
|
||||
;;
|
||||
--save | -w)
|
||||
@@ -5964,8 +5968,9 @@ nvm() {
|
||||
;;
|
||||
--lts) NVM_LTS='*' ; shift ;;
|
||||
--lts=*) NVM_LTS="${1##--lts=}" ; shift ;;
|
||||
--only=*)
|
||||
NVM_ONLY_FLAG="${1#--only=}"
|
||||
--only | --only=*)
|
||||
NVM_ONLY_FLAG="${1#--only}"
|
||||
NVM_ONLY_FLAG="${NVM_ONLY_FLAG#=}"
|
||||
NVM_ONLY_FLAG_COUNT=$((NVM_ONLY_FLAG_COUNT + 1))
|
||||
shift
|
||||
;;
|
||||
@@ -6074,8 +6079,9 @@ nvm() {
|
||||
--silent) NVM_SILENT=1 ; shift ;;
|
||||
--lts) NVM_LTS='*' ; shift ;;
|
||||
--lts=*) NVM_LTS="${1##--lts=}" ; shift ;;
|
||||
--only=*)
|
||||
NVM_ONLY_FLAG="${1#--only=}"
|
||||
--only | --only=*)
|
||||
NVM_ONLY_FLAG="${1#--only}"
|
||||
NVM_ONLY_FLAG="${NVM_ONLY_FLAG#=}"
|
||||
NVM_ONLY_FLAG_COUNT=$((NVM_ONLY_FLAG_COUNT + 1))
|
||||
shift
|
||||
;;
|
||||
@@ -6172,8 +6178,9 @@ nvm() {
|
||||
--) ;;
|
||||
--no-colors) NVM_NO_COLORS="${1}" ;;
|
||||
--no-alias) NVM_NO_ALIAS="${1}" ;;
|
||||
--only=*)
|
||||
NVM_ONLY_FLAG="${1#--only=}"
|
||||
--only | --only=*)
|
||||
NVM_ONLY_FLAG="${1#--only}"
|
||||
NVM_ONLY_FLAG="${NVM_ONLY_FLAG#=}"
|
||||
NVM_ONLY_FLAG_COUNT=$((NVM_ONLY_FLAG_COUNT + 1))
|
||||
;;
|
||||
--*)
|
||||
@@ -6224,8 +6231,9 @@ nvm() {
|
||||
--lts=*)
|
||||
NVM_LTS="${1##--lts=}"
|
||||
;;
|
||||
--only=*)
|
||||
NVM_ONLY_FLAG="${1#--only=}"
|
||||
--only | --only=*)
|
||||
NVM_ONLY_FLAG="${1#--only}"
|
||||
NVM_ONLY_FLAG="${NVM_ONLY_FLAG#=}"
|
||||
NVM_ONLY_FLAG_COUNT=$((NVM_ONLY_FLAG_COUNT + 1))
|
||||
;;
|
||||
--no-colors) NVM_NO_COLORS="${1}" ;;
|
||||
@@ -6289,8 +6297,9 @@ nvm() {
|
||||
case "${1}" in
|
||||
--silent) NVM_SILENT=1 ;;
|
||||
--) ;;
|
||||
--only=*)
|
||||
NVM_ONLY_FLAG="${1#--only=}"
|
||||
--only | --only=*)
|
||||
NVM_ONLY_FLAG="${1#--only}"
|
||||
NVM_ONLY_FLAG="${NVM_ONLY_FLAG#=}"
|
||||
NVM_ONLY_FLAG_COUNT=$((NVM_ONLY_FLAG_COUNT + 1))
|
||||
;;
|
||||
*) provided_version="${1-}" ;;
|
||||
@@ -6389,8 +6398,9 @@ nvm() {
|
||||
esac
|
||||
NVM_ALIAS_FLAGS="${1}"
|
||||
;;
|
||||
--only=*)
|
||||
NVM_ONLY_FLAG="${1#--only=}"
|
||||
--only | --only=*)
|
||||
NVM_ONLY_FLAG="${1#--only}"
|
||||
NVM_ONLY_FLAG="${NVM_ONLY_FLAG#=}"
|
||||
NVM_ONLY_FLAG_COUNT=$((NVM_ONLY_FLAG_COUNT + 1))
|
||||
;;
|
||||
--*)
|
||||
@@ -6515,8 +6525,9 @@ nvm() {
|
||||
NVM_REINSTALL_ARGS=0
|
||||
while [ $# -ne 0 ]; do
|
||||
case "${1}" in
|
||||
--only=*)
|
||||
NVM_ONLY_FLAG="${1#--only=}"
|
||||
--only | --only=*)
|
||||
NVM_ONLY_FLAG="${1#--only}"
|
||||
NVM_ONLY_FLAG="${NVM_ONLY_FLAG#=}"
|
||||
NVM_ONLY_FLAG_COUNT=$((NVM_ONLY_FLAG_COUNT + 1))
|
||||
;;
|
||||
*)
|
||||
@@ -6595,8 +6606,9 @@ nvm() {
|
||||
PATTERN=''
|
||||
while [ $# -gt 0 ]; do
|
||||
case "${1}" in
|
||||
--only=*)
|
||||
NVM_ONLY_FLAG="${1#--only=}"
|
||||
--only | --only=*)
|
||||
NVM_ONLY_FLAG="${1#--only}"
|
||||
NVM_ONLY_FLAG="${NVM_ONLY_FLAG#=}"
|
||||
NVM_ONLY_FLAG_COUNT=$((NVM_ONLY_FLAG_COUNT + 1))
|
||||
;;
|
||||
*) PATTERN="${PATTERN:-${1}}" ;;
|
||||
@@ -6622,8 +6634,9 @@ nvm() {
|
||||
--lts=*)
|
||||
NVM_LTS="${1##--lts=}"
|
||||
;;
|
||||
--only=*)
|
||||
NVM_ONLY_FLAG="${1#--only=}"
|
||||
--only | --only=*)
|
||||
NVM_ONLY_FLAG="${1#--only}"
|
||||
NVM_ONLY_FLAG="${NVM_ONLY_FLAG#=}"
|
||||
NVM_ONLY_FLAG_COUNT=$((NVM_ONLY_FLAG_COUNT + 1))
|
||||
;;
|
||||
--*)
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
cleanup () {
|
||||
NVM_DIR="${ORIG_NVM_DIR}"
|
||||
rm -rf "${TMP_DIR}"
|
||||
}
|
||||
|
||||
: nvm.sh
|
||||
\. ../../../nvm.sh
|
||||
|
||||
\. ../../common.sh
|
||||
|
||||
unset NVM_ONLY NVM_ONLY_SELECTED
|
||||
NVM_INDEX_NO_FETCH=1
|
||||
export NVM_INDEX_NO_FETCH
|
||||
nvm_download() { return 1; }
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
ORIG_NVM_DIR="${NVM_DIR}"
|
||||
NVM_DIR="${TMP_DIR}"
|
||||
|
||||
EXPECTED='Invalid `--only` value "": it must be a comma-separated list of any of: alpha, lts, non-lts, iojs'
|
||||
|
||||
# args: the flag, then nvm's arguments, with `@` where the flag goes
|
||||
try_with_flag () {
|
||||
FLAG="$1"
|
||||
shift
|
||||
ARG_COUNT=$#
|
||||
for ARG in "$@"; do
|
||||
if [ "${ARG}" = '@' ]; then
|
||||
set -- "$@" "${FLAG}"
|
||||
else
|
||||
set -- "$@" "${ARG}"
|
||||
fi
|
||||
done
|
||||
shift "${ARG_COUNT}"
|
||||
COMMAND_LINE="nvm $*"
|
||||
try_err nvm "$@"
|
||||
}
|
||||
|
||||
# args: nvm's arguments, with `@` where `--only=` or `--only` goes
|
||||
check () {
|
||||
for FLAG in --only= --only; do
|
||||
try_with_flag "${FLAG}" "$@"
|
||||
[ "_${CAPTURED_EXIT_CODE}" = '_55' ] || die "${COMMAND_LINE} exited ${CAPTURED_EXIT_CODE}, expected 55"
|
||||
[ "_${CAPTURED_STDERR}" = "_${EXPECTED}" ] || die "${COMMAND_LINE} printed >${CAPTURED_STDERR}<, expected >${EXPECTED}<"
|
||||
done
|
||||
}
|
||||
|
||||
check install @ 20
|
||||
check install 20 @
|
||||
check uninstall @ 20
|
||||
check use @ 20
|
||||
check run @ 20 --version
|
||||
check exec @ 20 node --version
|
||||
check ls @
|
||||
check ls-remote @
|
||||
check which @ 20
|
||||
check alias foo @ 20
|
||||
check reinstall-packages @ 20
|
||||
check version @ 20
|
||||
check version-remote @ 20
|
||||
|
||||
cleanup
|
||||
Reference in new issue
Block a user