[refactor] `nvm run`: refactor argument parsing.

Jordan Harband 2016-05-04 00:35:43 -07:00
parent 0d62626ac6
commit e8355e3189
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
1 changed files with 17 additions and 9 deletions

26
nvm.sh
View File

@ -2108,14 +2108,22 @@ nvm() {
shift
local NVM_SILENT
NVM_SILENT=0
if [ "_$1" = "_--silent" ]; then
NVM_SILENT=1
shift
fi
while [ $# -gt 0 ]
do
case "$1" in
--silent) NVM_SILENT='--silent' ; shift ;;
*)
if [ -n "$1" ]; then
break
else
shift
fi
;; # stop processing arguments
esac
done
if [ $# -lt 1 ]; then
if [ "$NVM_SILENT" -eq 1 ]; then
if [ -n "${NVM_SILENT-}" ]; then
nvm_rc_version >/dev/null 2>&1 && has_checked_nvmrc=1
else
nvm_rc_version && has_checked_nvmrc=1
@ -2137,7 +2145,7 @@ nvm() {
if [ "_$VERSION" = "_N/A" ] && ! nvm_is_valid_version "$provided_version"; then
provided_version=''
if [ $has_checked_nvmrc -ne 1 ]; then
if [ "$NVM_SILENT" -eq 1 ]; then
if [ -n "${NVM_SILENT-}" ]; then
nvm_rc_version >/dev/null 2>&1 && has_checked_nvmrc=1
else
nvm_rc_version && has_checked_nvmrc=1
@ -2176,11 +2184,11 @@ nvm() {
fi
EXIT_CODE="$?"
elif [ "$NVM_IOJS" = true ]; then
[ $NVM_SILENT -eq 1 ] || echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm use --silent "$VERSION" && nvm_print_npm_version)"
[ -n "${NVM_SILENT-}" ] || echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm use --silent "$VERSION" && nvm_print_npm_version)"
OUTPUT="$(nvm use "$VERSION" >/dev/null && iojs $ARGS)"
EXIT_CODE="$?"
else
[ $NVM_SILENT -eq 1 ] || echo "Running node $VERSION$(nvm use --silent "$VERSION" && nvm_print_npm_version)"
[ -n "${NVM_SILENT-}" ] || echo "Running node $VERSION$(nvm use --silent "$VERSION" && nvm_print_npm_version)"
OUTPUT="$(nvm use "$VERSION" >/dev/null && node $ARGS)"
EXIT_CODE="$?"
fi