From 643365a9481b8ae10635c4a68390820ad285a0ae Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 20 Sep 2015 19:45:53 -0700 Subject: [PATCH] Allow `--silent` option to `nvm use` to be in any position. --- nvm.sh | 18 +++++++++++++----- ...\"nvm use iojs\" uses latest io.js version" | 8 ++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/nvm.sh b/nvm.sh index ad6e630..eb03559 100755 --- a/nvm.sh +++ b/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 diff --git "a/test/fast/Running \"nvm use iojs\" uses latest io.js version" "b/test/fast/Running \"nvm use iojs\" uses latest io.js version" index 97c45eb..edee505 100755 --- "a/test/fast/Running \"nvm use iojs\" uses latest io.js version" +++ "b/test/fast/Running \"nvm use iojs\" uses latest io.js version" @@ -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;