Allow `--silent` option to `nvm use` to be in any position.
parent
6e894520ec
commit
643365a948
18
nvm.sh
18
nvm.sh
|
@ -1557,19 +1557,27 @@ nvm() {
|
|||
local PROVIDED_VERSION
|
||||
local NVM_USE_SILENT
|
||||
NVM_USE_SILENT=0
|
||||
if [ "$2" = '--silent' ]; then
|
||||
NVM_USE_SILENT=1
|
||||
shift # remove "use"
|
||||
while [ $# -ne 0 ]
|
||||
do
|
||||
case "$1" in
|
||||
--silent) NVM_USE_SILENT=1 ;;
|
||||
*)
|
||||
if [ -n "$1" ]; then
|
||||
PROVIDED_VERSION="$1"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $# -eq 1 ]; then
|
||||
if [ -z "$PROVIDED_VERSION" ]; then
|
||||
nvm_rc_version
|
||||
if [ -n "$NVM_RC_VERSION" ]; then
|
||||
PROVIDED_VERSION="$NVM_RC_VERSION"
|
||||
VERSION="$(nvm_version "$PROVIDED_VERSION")"
|
||||
fi
|
||||
else
|
||||
PROVIDED_VERSION="$2"
|
||||
VERSION="$(nvm_match_version "$PROVIDED_VERSION")"
|
||||
fi
|
||||
|
||||
|
|
|
@ -23,8 +23,16 @@ EXPECTED_OUTPUT=''
|
|||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
||||
|| die "'nvm use --silent foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||
|
||||
OUTPUT="$(nvm use foo --silent 2>&1)"
|
||||
EXPECTED_OUTPUT=''
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
||||
|| die "'nvm use foo --silent' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||
|
||||
EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)"
|
||||
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8 from 'nvm use --silent foo'; got $EXIT_CODE"
|
||||
|
||||
EXIT_CODE="$(nvm use foo --silent 2>/dev/null ; echo $?)"
|
||||
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8 from 'nvm use foo --silent'; got $EXIT_CODE"
|
||||
|
||||
cleanup;
|
||||
|
||||
|
|
Loading…
Reference in New Issue