Merge pull request #436 from koenpunt/stderr

redirect output of errors to stderr
master
Jordan Harband 2014-06-16 16:37:31 -07:00
commit 9a28706688
3 changed files with 43 additions and 43 deletions

82
nvm.sh
View File

@ -138,8 +138,8 @@ nvm_ls() {
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | grep -v '^ *\.'` | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | grep -v '^ *\.'`
fi fi
if [ -z "$VERSIONS" ]; then if [ -z "$VERSIONS" ]; then
echo "N/A" echo "N/A"
return return
fi fi
echo "$VERSIONS" echo "$VERSIONS"
return return
@ -181,7 +181,7 @@ nvm_checksum() {
echo 'Checksums empty' #missing in raspberry pi binary echo 'Checksums empty' #missing in raspberry pi binary
return return
else else
echo 'Checksums do not match.' echo 'Checksums do not match.' >&2
return 1 return 1
fi fi
} }
@ -308,7 +308,7 @@ nvm() {
fi fi
provided_version="$NVM_RC_VERSION" provided_version="$NVM_RC_VERSION"
fi fi
[ -d "$NVM_DIR/$provided_version" ] && echo "$provided_version is already installed." && return [ -d "$NVM_DIR/$provided_version" ] && echo "$provided_version is already installed." >&2 && return
VERSION=`nvm_remote_version $provided_version` VERSION=`nvm_remote_version $provided_version`
ADDITIONAL_PARAMETERS='' ADDITIONAL_PARAMETERS=''
@ -322,13 +322,13 @@ nvm() {
done done
if [ -d "$NVM_DIR/$VERSION" ]; then if [ -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION is already installed." echo "$VERSION is already installed." >&2
nvm use "$VERSION" nvm use "$VERSION"
return $? return $?
fi fi
if [ "$VERSION" = "N/A" ]; then if [ "$VERSION" = "N/A" ]; then
echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions." echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions." >&2
return 3 return 3
fi fi
@ -395,10 +395,10 @@ nvm() {
if ! nvm_has "npm" ; then if ! nvm_has "npm" ; then
echo "Installing npm..." echo "Installing npm..."
if [ "`expr "$VERSION" : '\(^v0\.1\.\)'`" != '' ]; then if [ "`expr "$VERSION" : '\(^v0\.1\.\)'`" != '' ]; then
echo "npm requires node v0.2.3 or higher" echo "npm requires node v0.2.3 or higher" >&2
elif [ "`expr "$VERSION" : '\(^v0\.2\.\)'`" != '' ]; then elif [ "`expr "$VERSION" : '\(^v0\.2\.\)'`" != '' ]; then
if [ "`expr "$VERSION" : '\(^v0\.2\.[0-2]$\)'`" != '' ]; then if [ "`expr "$VERSION" : '\(^v0\.2\.[0-2]$\)'`" != '' ]; then
echo "npm requires node v0.2.3 or higher" echo "npm requires node v0.2.3 or higher" >&2
else else
curl https://npmjs.org/install.sh | clean=yes npm_install=0.2.19 sh curl https://npmjs.org/install.sh | clean=yes npm_install=0.2.19 sh
fi fi
@ -407,7 +407,7 @@ nvm() {
fi fi
fi fi
else else
echo "nvm: install $VERSION failed!" echo "nvm: install $VERSION failed!" >&2
return 1 return 1
fi fi
;; ;;
@ -415,12 +415,12 @@ nvm() {
[ $# -ne 2 ] && nvm help && return [ $# -ne 2 ] && nvm help && return
PATTERN=`nvm_format_version $2` PATTERN=`nvm_format_version $2`
if [ "$PATTERN" = `nvm_version` ]; then if [ "$PATTERN" = `nvm_version` ]; then
echo "nvm: Cannot uninstall currently-active node version, $PATTERN." echo "nvm: Cannot uninstall currently-active node version, $PATTERN." >&2
return 1 return 1
fi fi
VERSION=`nvm_version $PATTERN` VERSION=`nvm_version $PATTERN`
if [ ! -d $NVM_DIR/$VERSION ]; then if [ ! -d $NVM_DIR/$VERSION ]; then
echo "$VERSION version is not installed..." echo "$VERSION version is not installed..." >&2
return; return;
fi fi
@ -447,19 +447,19 @@ nvm() {
hash -r hash -r
echo "$NVM_DIR/*/bin removed from \$PATH" echo "$NVM_DIR/*/bin removed from \$PATH"
else else
echo "Could not find $NVM_DIR/*/bin in \$PATH" echo "Could not find $NVM_DIR/*/bin in \$PATH" >&2
fi fi
if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then
export MANPATH=`nvm_strip_path "$MANPATH" "/share/man"` export MANPATH=`nvm_strip_path "$MANPATH" "/share/man"`
echo "$NVM_DIR/*/share/man removed from \$MANPATH" echo "$NVM_DIR/*/share/man removed from \$MANPATH"
else else
echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" >&2
fi fi
if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ] ; then if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ] ; then
export NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"` export NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH" echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH"
else else
echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH" echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH" >&2
fi fi
;; ;;
"use" ) "use" )
@ -470,7 +470,7 @@ nvm() {
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
nvm_rc_version nvm_rc_version
if [ -n "$NVM_RC_VERSION" ]; then if [ -n "$NVM_RC_VERSION" ]; then
VERSION=`nvm_version $NVM_RC_VERSION` VERSION=`nvm_version $NVM_RC_VERSION`
fi fi
else else
VERSION=`nvm_version $2` VERSION=`nvm_version $2`
@ -483,7 +483,7 @@ nvm() {
VERSION=`nvm_version $2` VERSION=`nvm_version $2`
fi fi
if [ ! -d "$NVM_DIR/$VERSION" ]; then if [ ! -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION version is not installed yet" echo "$VERSION version is not installed yet" >&2
return 1 return 1
fi fi
# Strip other version from PATH # Strip other version from PATH
@ -542,7 +542,7 @@ nvm() {
fi fi
if [ ! -d "$NVM_DIR/$VERSION" ]; then if [ ! -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION version is not installed yet" echo "$VERSION version is not installed yet" >&2
return; return;
fi fi
RUN_NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"` RUN_NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
@ -558,8 +558,8 @@ nvm() {
return return
;; ;;
"ls-remote" | "list-remote" ) "ls-remote" | "list-remote" )
nvm_print_versions "`nvm_ls_remote $2`" nvm_print_versions "`nvm_ls_remote $2`"
return return
;; ;;
"current" ) "current" )
nvm_version current nvm_version current
@ -573,18 +573,18 @@ nvm() {
DEST=`cat $ALIAS` DEST=`cat $ALIAS`
VERSION=`nvm_version $DEST` VERSION=`nvm_version $DEST`
if [ "$DEST" = "$VERSION" ]; then if [ "$DEST" = "$VERSION" ]; then
echo "$(basename $ALIAS) -> $DEST" echo "$(basename $ALIAS) -> $DEST"
else else
echo "$(basename $ALIAS) -> $DEST (-> $VERSION)" echo "$(basename $ALIAS) -> $DEST (-> $VERSION)"
fi fi
fi fi
done done
return return
fi fi
if [ -z "$3" ]; then if [ -z "$3" ]; then
rm -f $NVM_DIR/alias/$2 rm -f $NVM_DIR/alias/$2
echo "$2 -> *poof*" echo "$2 -> *poof*"
return return
fi fi
mkdir -p $NVM_DIR/alias mkdir -p $NVM_DIR/alias
VERSION=`nvm_version $3` VERSION=`nvm_version $3`
@ -593,7 +593,7 @@ nvm() {
fi fi
echo $3 > "$NVM_DIR/alias/$2" echo $3 > "$NVM_DIR/alias/$2"
if [ ! "$3" = "$VERSION" ]; then if [ ! "$3" = "$VERSION" ]; then
echo "$2 -> $3 (-> $VERSION)" echo "$2 -> $3 (-> $VERSION)"
else else
echo "$2 -> $3" echo "$2 -> $3"
fi fi
@ -601,34 +601,34 @@ nvm() {
"unalias" ) "unalias" )
mkdir -p $NVM_DIR/alias mkdir -p $NVM_DIR/alias
[ $# -ne 2 ] && nvm help && return 127 [ $# -ne 2 ] && nvm help && return 127
[ ! -f "$NVM_DIR/alias/$2" ] && echo "Alias $2 doesn't exist!" && return [ ! -f "$NVM_DIR/alias/$2" ] && echo "Alias $2 doesn't exist!" >&2 && return
rm -f $NVM_DIR/alias/$2 rm -f $NVM_DIR/alias/$2
echo "Deleted alias $2" echo "Deleted alias $2"
;; ;;
"copy-packages" ) "copy-packages" )
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
nvm help nvm help
return 127 return 127
fi fi
VERSION=`nvm_version $2` VERSION=`nvm_version $2`
local ROOT=`(nvm use $VERSION && npm -g root)` local ROOT=`(nvm use $VERSION && npm -g root)`
local ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1)) local ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1))
# declare local INSTALLS first, otherwise it doesn't work in zsh # declare local INSTALLS first, otherwise it doesn't work in zsh
local INSTALLS local INSTALLS
INSTALLS=`nvm use $VERSION > /dev/null && npm -g -p ll | \grep "$ROOT\/[^/]\+$" | cut -d '/' -f $(($ROOTDEPTH + 2)) | cut -d ":" -f 2 | \grep -v npm | tr "\n" " "` INSTALLS=`nvm use $VERSION > /dev/null && npm -g -p ll | \grep "$ROOT\/[^/]\+$" | cut -d '/' -f $(($ROOTDEPTH + 2)) | cut -d ":" -f 2 | \grep -v npm | tr "\n" " "`
npm install -g ${INSTALLS[@]} npm install -g ${INSTALLS[@]}
;; ;;
"clear-cache" ) "clear-cache" )
rm -f $NVM_DIR/v* 2>/dev/null rm -f $NVM_DIR/v* 2>/dev/null
echo "Cache cleared." echo "Cache cleared."
;; ;;
"version" ) "version" )
nvm_version $2 nvm_version $2
;; ;;
"--version" ) "--version" )
echo "0.7.0" echo "0.7.0"
;; ;;
"unload" ) "unload" )
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version > /dev/null 2>&1 unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version > /dev/null 2>&1

View File

@ -3,5 +3,5 @@
die () { echo $@ ; exit 1; } die () { echo $@ ; exit 1; }
. ../../nvm.sh . ../../nvm.sh
[ "$(nvm install invalid.invalid)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message" [ "$(nvm install invalid.invalid 2>&1)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message"

View File

@ -4,7 +4,7 @@ die () { echo $@ ; exit 1; }
. ../../../nvm.sh . ../../../nvm.sh
[ "$(nvm install invalid.invalid)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message" [ "$(nvm install invalid.invalid 2>&1)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message"
# Remove the stuff we're clobbering. # Remove the stuff we're clobbering.
[ -e ../../../v0.9.7 ] && rm -R ../../../v0.9.7 [ -e ../../../v0.9.7 ] && rm -R ../../../v0.9.7