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

Jordan Harband 2016-05-04 00:34:07 -07:00
parent 6fb94e0dab
commit 0d62626ac6
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
1 changed files with 20 additions and 7 deletions

23
nvm.sh
View File

@ -2196,18 +2196,31 @@ nvm() {
shift shift
local NVM_SILENT local NVM_SILENT
NVM_SILENT=0 while [ $# -gt 0 ]
if [ "_$1" = "_--silent" ]; then do
NVM_SILENT=1 case "$1" in
--silent) NVM_SILENT='--silent' ; shift ;;
--) break ;;
--*)
>&2 echo "Unsupported option "$1"."
return 55
;;
*)
if [ -n "$1" ]; then
break
else
shift shift
fi fi
;; # stop processing arguments
esac
done
local provided_version local provided_version
provided_version="$1" provided_version="$1"
if [ -n "$provided_version" ]; then if [ -n "$provided_version" ]; then
VERSION="$(nvm_version "$provided_version" || return 0)" VERSION="$(nvm_version "$provided_version" || return 0)"
if [ "_$VERSION" = "_N/A" ] && ! nvm_is_valid_version "$provided_version"; then if [ "_$VERSION" = "_N/A" ] && ! nvm_is_valid_version "$provided_version"; then
if [ "$NVM_SILENT" -eq 1 ]; then if [ -n "${NVM_SILENT-}" ]; then
nvm_rc_version >/dev/null 2>&1 nvm_rc_version >/dev/null 2>&1
else else
nvm_rc_version nvm_rc_version
@ -2225,7 +2238,7 @@ nvm() {
return $EXIT_CODE return $EXIT_CODE
fi fi
if [ "${NVM_SILENT:-0}" != '1' ]; then if [ -z "${NVM_SILENT-}" ]; then
if nvm_is_iojs_version "$VERSION"; then if nvm_is_iojs_version "$VERSION"; then
echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm use --silent "$VERSION" && nvm_print_npm_version)" echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm use --silent "$VERSION" && nvm_print_npm_version)"
else else