From 3a242147de82b1f579b9c1738b5c81c0e8dcd72e Mon Sep 17 00:00:00 2001 From: "Bickel, Korbin" Date: Thu, 13 Dec 2018 14:54:23 -0500 Subject: [PATCH] Combine all parameters into single case. Removes all order dependance (except optional compile params, which must come after all install params in order to not be confused with the optional version param). --- nvm.sh | 68 ++++++++++++++++++++++++---------------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/nvm.sh b/nvm.sh index 3c5e846..f812ca7 100644 --- a/nvm.sh +++ b/nvm.sh @@ -2485,49 +2485,36 @@ nvm() { local LTS local NVM_UPGRADE_NPM NVM_UPGRADE_NPM=0 - while [ $# -ne 0 ] - do - case "$1" in - -s) - shift # consume "-s" - nobinary=1 - ;; - -j) - shift # consume "-j" - nvm_get_make_jobs "$1" - shift # consume job count - ;; - --no-progress) - noprogress=1 - shift - ;; - --lts) - LTS='*' - shift - ;; - --lts=*) - LTS="${1##--lts=}" - shift - ;; - --latest-npm) - NVM_UPGRADE_NPM=1 - shift - ;; - *) - break # stop parsing args - ;; - esac - done - - ADDITIONAL_PARAMETERS='' local PROVIDED_REINSTALL_PACKAGES_FROM local REINSTALL_PACKAGES_FROM local SKIP_DEFAULT_PACKAGES local DEFAULT_PACKAGES + local provided_version='' + ADDITIONAL_PARAMETERS='' + while [ $# -ne 0 ] do case "$1" in + -s) + nobinary=1 + ;; + -j) + shift # 2 part parameter, comsume first part now + nvm_get_make_jobs "$1" # $1 is now second parameter piece + ;; + --no-progress) + noprogress=1 + ;; + --lts) + LTS='*' + ;; + --lts=*) + LTS="${1##--lts=}" + ;; + --latest-npm) + NVM_UPGRADE_NPM=1 + ;; --reinstall-packages-from=*) PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 27-)" if [ -z "${PROVIDED_REINSTALL_PACKAGES_FROM}" ]; then @@ -2548,15 +2535,16 @@ nvm() { SKIP_DEFAULT_PACKAGES=true ;; *) - ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1" + if [ -z "$provided_version" ]; then + provided_version="$1" + else + ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1" # gather all other parameters + fi ;; esac - shift + shift # consume parameter done - local provided_version - provided_version="${1-}" - if [ -z "$provided_version" ]; then if [ "_${LTS-}" = '_*' ]; then nvm_echo 'Installing latest LTS version.'