diff --git a/nvm.sh b/nvm.sh index dcca451..43d7795 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1187,7 +1187,7 @@ nvm() { echo " nvm --version Print out the latest released version of nvm" echo " nvm install [-s] Download and install a , [-s] from source. Uses .nvmrc if available" echo " nvm uninstall Uninstall a version" - echo " nvm use Modify PATH to use . Uses .nvmrc if available" + echo " nvm use [--silent] Modify PATH to use . Uses .nvmrc if available" echo " nvm run [] Run with as arguments. Uses .nvmrc if available for " echo " nvm current Display currently activated version" echo " nvm ls List installed versions" @@ -1445,6 +1445,13 @@ nvm() { ;; "use" ) local PROVIDED_VERSION + local silent + silent=0 + if [ "$2" = '--silent' ]; then + silent=1 + shift + fi + if [ $# -eq 1 ]; then nvm_rc_version if [ -n "$NVM_RC_VERSION" ]; then @@ -1463,17 +1470,25 @@ nvm() { if [ "_$VERSION" = '_system' ]; then if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then - echo "Now using system version of node: $(node -v 2>/dev/null)$(nvm_print_npm_version)" + if [ $silent -ne 1 ]; then + echo "Now using system version of node: $(node -v 2>/dev/null)$(nvm_print_npm_version)" + fi return elif nvm_has_system_iojs && nvm deactivate >/dev/null 2>&1; then - echo "Now using system version of io.js: $(iojs --version 2>/dev/null)$(nvm_print_npm_version)" + if [ $silent -ne 1 ]; then + echo "Now using system version of io.js: $(iojs --version 2>/dev/null)$(nvm_print_npm_version)" + fi return else - echo "System version of node not found." >&2 + if [ $silent -ne 1 ]; then + echo "System version of node not found." >&2 + fi return 127 fi elif [ "_$VERSION" = "_∞" ]; then - echo "The alias \"$PROVIDED_VERSION\" leads to an infinite loop. Aborting." >&2 + if [ $silent -ne 1 ]; then + echo "The alias \"$PROVIDED_VERSION\" leads to an infinite loop. Aborting." >&2 + fi return 8 fi @@ -1510,9 +1525,13 @@ nvm() { command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current" fi if nvm_is_iojs_version "$VERSION"; then - echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)" + if [ $silent -ne 1 ]; then + echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)" + fi else - echo "Now using node $VERSION$(nvm_print_npm_version)" + if [ $silent -ne 1 ]; then + echo "Now using node $VERSION$(nvm_print_npm_version)" + fi fi ;; "run" ) @@ -1882,9 +1901,9 @@ if nvm_supports_source_options && [ "_$1" = "_--install" ]; then nvm install >/dev/null fi elif [ -n "$VERSION" ]; then - nvm use "$VERSION" >/dev/null + nvm use --silent "$VERSION" >/dev/null elif nvm_rc_version >/dev/null 2>&1; then - nvm use >/dev/null + nvm use --silent >/dev/null fi } # this ensures the entire script is downloaded # diff --git "a/test/fast/Running \"nvm use foo\" where \"foo\" is circular aborts" "b/test/fast/Running \"nvm use foo\" where \"foo\" is circular aborts" index 53f67fa..97c45eb 100755 --- "a/test/fast/Running \"nvm use foo\" where \"foo\" is circular aborts" +++ "b/test/fast/Running \"nvm use foo\" where \"foo\" is circular aborts" @@ -18,5 +18,13 @@ EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.' EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)" [ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE" +OUTPUT="$(nvm use --silent foo 2>&1)" +EXPECTED_OUTPUT='' +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ + || die "'nvm use --silent foo' 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" + cleanup; 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 53f67fa..97c45eb 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" @@ -18,5 +18,13 @@ EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.' EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)" [ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE" +OUTPUT="$(nvm use --silent foo 2>&1)" +EXPECTED_OUTPUT='' +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ + || die "'nvm use --silent foo' 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" + cleanup; diff --git "a/test/fast/Running \"nvm use system\" should work as expected" "b/test/fast/Running \"nvm use system\" should work as expected" index 86a0955..4eb3319 100755 --- "a/test/fast/Running \"nvm use system\" should work as expected" +++ "b/test/fast/Running \"nvm use system\" should work as expected" @@ -8,10 +8,15 @@ nvm_has_system_node() { return 0; } nvm_print_npm_version() { return ' (npm v1.2.3)'; } EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)" [ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node" +EXPECTED_OUTPUT="" +[ "$(nvm use --silent system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node or --silent was not silent" nvm_has_system_node() { return 1; } nvm_print_npm_version() { return ''; } EXPECTED_OUTPUT="System version of node not found." [ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found" nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found" +EXPECTED_OUTPUT="" +[ "$(nvm use --silent system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found or --silent was not silent" +nvm use --silent system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found or --silent was not silent" diff --git "a/test/slow/nvm use/Running \"nvm use iojs\" uses latest io.js version" "b/test/slow/nvm use/Running \"nvm use iojs\" uses latest io.js version" index 5b867f3..506ff86 100755 --- "a/test/slow/nvm use/Running \"nvm use iojs\" uses latest io.js version" +++ "b/test/slow/nvm use/Running \"nvm use iojs\" uses latest io.js version" @@ -12,3 +12,9 @@ EXPECTED_OUTPUT="iojs-v1.0.1" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ || die "'nvm use iojs' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'" + +OUTPUT="$(nvm use --silent iojs)" +EXPECTED_OUTPUT="" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ + || die "'nvm use --silent iojs' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'" diff --git "a/test/slow/nvm use/Running \"nvm use node\" uses latest stable node version" "b/test/slow/nvm use/Running \"nvm use node\" uses latest stable node version" index 3514256..ce84bb6 100755 --- "a/test/slow/nvm use/Running \"nvm use node\" uses latest stable node version" +++ "b/test/slow/nvm use/Running \"nvm use node\" uses latest stable node version" @@ -12,3 +12,9 @@ EXPECTED_OUTPUT="$(nvm_version stable)" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ || die "'nvm use node' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'" + +OUTPUT="$(nvm use --silent node)" +EXPECTED_OUTPUT="" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ + || die "'nvm use --silent node' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'" diff --git "a/test/slow/nvm use/Running \"nvm use v1.0.0\" uses iojs-v1.0.0 iojs version" "b/test/slow/nvm use/Running \"nvm use v1.0.0\" uses iojs-v1.0.0 iojs version" index f2a2062..2416c79 100755 --- "a/test/slow/nvm use/Running \"nvm use v1.0.0\" uses iojs-v1.0.0 iojs version" +++ "b/test/slow/nvm use/Running \"nvm use v1.0.0\" uses iojs-v1.0.0 iojs version" @@ -12,3 +12,9 @@ EXPECTED_OUTPUT="$(nvm_version v1.0.0)" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ || die "'nvm use v1.0.0' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'" + +OUTPUT="$(nvm use --silent 'v1.0.0')" +EXPECTED_OUTPUT="" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ + || die "'nvm use --silent v1.0.0' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'"