Add support for `--silent` to `nvm run` and `nvm exec`.

Fixes #842.
Jordan Harband 2015-09-23 05:16:45 -07:00
parent 7496a24bd6
commit eb81fba8f7
1 changed files with 39 additions and 24 deletions

25
nvm.sh
View File

@ -1285,8 +1285,8 @@ nvm() {
echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'
echo ' nvm uninstall <version> Uninstall a version'
echo ' nvm use [--silent] <version> Modify PATH to use <version>. Uses .nvmrc if available'
echo ' nvm exec <version> [<command>] Run <command> on <version>. Uses .nvmrc if available for <version>'
echo ' nvm run <version> [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available for <version>'
echo ' nvm exec [--silent] <version> [<command>] Run <command> on <version>. Uses .nvmrc if available'
echo ' nvm run [--silent] <version> [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available'
echo ' nvm current Display currently activated version'
echo ' nvm ls List installed versions'
echo ' nvm ls <version> List versions matching a given description'
@ -1659,6 +1659,14 @@ nvm() {
has_checked_nvmrc=0
# run given version of node
shift
local NVM_SILENT
NVM_SILENT=0
if [ "_$1" = "_--silent" ]; then
NVM_SILENT=1
shift
fi
if [ $# -lt 1 ]; then
nvm_rc_version && has_checked_nvmrc=1
if [ -n "$NVM_RC_VERSION" ]; then
@ -1713,11 +1721,11 @@ nvm() {
fi
EXIT_CODE="$?"
elif [ "$NVM_IOJS" = true ]; then
echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)"
[ $NVM_SILENT -eq 1 ] || echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)"
OUTPUT="$(nvm use "$VERSION" >/dev/null && iojs $ARGS)"
EXIT_CODE="$?"
else
echo "Running node $VERSION$(nvm_print_npm_version)"
[ $NVM_SILENT -eq 1 ] || echo "Running node $VERSION$(nvm_print_npm_version)"
OUTPUT="$(nvm use "$VERSION" >/dev/null && node $ARGS)"
EXIT_CODE="$?"
fi
@ -1732,6 +1740,13 @@ nvm() {
"exec" )
shift
local NVM_SILENT
NVM_SILENT=0
if [ "_$1" = "_--silent" ]; then
NVM_SILENT=1
shift
fi
local provided_version
provided_version="$1"
if [ -n "$provided_version" ]; then
@ -1751,7 +1766,7 @@ nvm() {
return $EXIT_CODE
fi
echo "Running node $VERSION$(nvm_print_npm_version)"
[ $NVM_SILENT -eq 1 ] || echo "Running node $VERSION$(nvm_print_npm_version)"
NODE_VERSION="$VERSION" $NVM_DIR/nvm-exec "$@"
;;
"ls" | "list" )