Skip to content
Myr

Merge pull request #780 from alanmquach/silent-source

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Adding --silent option for nvm use, and using it to disable processing certain output to speed up shell startup Relates to #781.

authored by Jordan Harband · committed by Jordan Harband · parents f2d31b0, 657192d · Browse files · 7 files+67 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+67 added−9 removed

  • tests:+39 added−0 removed
  • other:+28 added−9 removed

7 files+67 added−9 removed

modified:test/fast/Running "nvm use foo" where "foo" is circular aborts+8 added
16 unmodified lines
1718EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"19[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE"2021OUTPUT="$(nvm use --silent foo 2>&1)"22EXPECTED_OUTPUT=''23[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \24 || die "'nvm use --silent foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"2526EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)"27[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8 from 'nvm use --silent foo'; got $EXIT_CODE"2829cleanup;30
modified:test/fast/Running "nvm use iojs" uses latest io.js version+8 added
16 unmodified lines
1718EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"19[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE"2021OUTPUT="$(nvm use --silent foo 2>&1)"22EXPECTED_OUTPUT=''23[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \24 || die "'nvm use --silent foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"2526EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)"27[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8 from 'nvm use --silent foo'; got $EXIT_CODE"2829cleanup;30
modified:test/fast/Running "nvm use system" should work as expected+5 added
6 unmodified lines
7nvm_has_system_node() { return 0; }8nvm_print_npm_version() { return ' (npm v1.2.3)'; }9EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)"10[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node"11EXPECTED_OUTPUT=""12[ "$(nvm use --silent system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node or --silent was not silent"1314nvm_has_system_node() { return 1; }15nvm_print_npm_version() { return ''; }16EXPECTED_OUTPUT="System version of node not found."17[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found"18nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"19EXPECTED_OUTPUT=""20[ "$(nvm use --silent system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found or --silent was not silent"21nvm use --silent system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found or --silent was not silent"22
modified:test/slow/nvm use/Running "nvm use iojs" uses latest io.js version+6 added
10 unmodified lines
11EXPECTED_OUTPUT="iojs-v1.0.1"1213[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \14 || die "'nvm use iojs' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"1516OUTPUT="$(nvm use --silent iojs)"17EXPECTED_OUTPUT=""1819[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \20 || die "'nvm use --silent iojs' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'"
modified:test/slow/nvm use/Running "nvm use node" uses latest stable node version+6 added
10 unmodified lines
11EXPECTED_OUTPUT="$(nvm_version stable)"1213[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \14 || die "'nvm use node' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"1516OUTPUT="$(nvm use --silent node)"17EXPECTED_OUTPUT=""1819[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \20 || die "'nvm use --silent node' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'"
modified:test/slow/nvm use/Running "nvm use v1.0.0" uses iojs-v1.0.0 iojs version+6 added
10 unmodified lines
11EXPECTED_OUTPUT="$(nvm_version v1.0.0)"1213[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \14 || die "'nvm use v1.0.0' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"1516OUTPUT="$(nvm use --silent 'v1.0.0')"17EXPECTED_OUTPUT=""1819[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \20 || die "'nvm use --silent v1.0.0' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'"
modified:nvm.sh+28 added-9 removed
1185 unmodified lines
1186 echo " nvm help Show this message"1187 echo " nvm --version Print out the latest released version of nvm"1188 echo " nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available"1189 echo " nvm uninstall <version> Uninstall a version"1190 echo " nvm use <version> Modify PATH to use <version>. Uses .nvmrc if available"1190 echo " nvm use [--silent] <version> Modify PATH to use <version>. Uses .nvmrc if available"1191 echo " nvm run <version> [<args>] Run <version> with <args> as arguments. Uses .nvmrc if available for <version>"1192 echo " nvm current Display currently activated version"1193 echo " nvm ls List installed versions"1194 echo " nvm ls <version> List versions matching a given description"
249 unmodified lines
1444 fi1445 ;;1446 "use" )1447 local PROVIDED_VERSION1448 local silent1449 silent=01450 if [ "$2" = '--silent' ]; then1451 silent=11452 shift1453 fi14541455 if [ $# -eq 1 ]; then1456 nvm_rc_version1457 if [ -n "$NVM_RC_VERSION" ]; then1458 PROVIDED_VERSION="$NVM_RC_VERSION"
10 unmodified lines
1469 fi14701471 if [ "_$VERSION" = '_system' ]; then1472 if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then1473 if [ $silent -ne 1 ]; then1466 echo "Now using system version of node: $(node -v 2>/dev/null)$(nvm_print_npm_version)"1474 echo "Now using system version of node: $(node -v 2>/dev/null)$(nvm_print_npm_version)"1475 fi1476 return1477 elif nvm_has_system_iojs && nvm deactivate >/dev/null 2>&1; then1478 if [ $silent -ne 1 ]; then1469 echo "Now using system version of io.js: $(iojs --version 2>/dev/null)$(nvm_print_npm_version)"1479 echo "Now using system version of io.js: $(iojs --version 2>/dev/null)$(nvm_print_npm_version)"1480 fi1481 return1482 else1483 if [ $silent -ne 1 ]; then1472 echo "System version of node not found." >&21484 echo "System version of node not found." >&21485 fi1486 return 1271487 fi1488 elif [ "_$VERSION" = "_∞" ]; then1489 if [ $silent -ne 1 ]; then1476 echo "The alias \"$PROVIDED_VERSION\" leads to an infinite loop. Aborting." >&21490 echo "The alias \"$PROVIDED_VERSION\" leads to an infinite loop. Aborting." >&21491 fi1492 return 81493 fi14941495 # This nvm_ensure_version_installed call can be a performance bottleneck
28 unmodified lines
1524 if [ "$NVM_SYMLINK_CURRENT" = true ]; then1525 command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current"1526 fi1527 if nvm_is_iojs_version "$VERSION"; then1528 if [ $silent -ne 1 ]; then1513 echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)"1529 echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)"1530 fi1531 else1532 if [ $silent -ne 1 ]; then1515 echo "Now using node $VERSION$(nvm_print_npm_version)"1533 echo "Now using node $VERSION$(nvm_print_npm_version)"1534 fi1535 fi1536 ;;1537 "run" )1538 local provided_version
361 unmodified lines
1900 elif nvm_rc_version >/dev/null 2>&1; then1901 nvm install >/dev/null1902 fi1903elif [ -n "$VERSION" ]; then1885 nvm use "$VERSION" >/dev/null1904 nvm use --silent "$VERSION" >/dev/null1905elif nvm_rc_version >/dev/null 2>&1; then1887 nvm use >/dev/null1906 nvm use --silent >/dev/null1907fi19081909} # this ensures the entire script is downloaded #