Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process additional (--) parameters before final version parameter. #1957

Open
wants to merge 7 commits into
base: master
from

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).
  • Loading branch information...
Bickel, Korbin
Bickel, Korbin committed Dec 13, 2018
commit 3a242147de82b1f579b9c1738b5c81c0e8dcd72e
44 nvm.sh
@@ -2485,49 +2485,36 @@ nvm() {
local LTS
local NVM_UPGRADE_NPM
NVM_UPGRADE_NPM=0
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)
shift # consume "-s"
nobinary=1
;;
-j)
shift # consume "-j"
nvm_get_make_jobs "$1"
shift # consume job count
shift # 2 part parameter, comsume first part now
nvm_get_make_jobs "$1" # $1 is now second parameter piece

This comment has been minimized.

Copy link
@ljharb

ljharb Dec 13, 2018

Member

it looks like the job count is now consumed into ADDITIONAL_PARAMETERS?

This comment has been minimized.

Copy link
@leebickmtu

leebickmtu Dec 14, 2018

Author

ADDITIONAL_PARAMETERS is only added to if the parameter does not meet the other cases above it. The job count parameter is it's own case. So it is not added to ADDITIONAL_PARAMETERS.

This comment has been minimized.

Copy link
@ljharb

ljharb Dec 15, 2018

Member

which line handles that? note that nvm install and nvm use, with no "provided version" argument (but still with possible additional parameters) are also valid use case (they'll read from .nvmrc)

;;
--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

while [ $# -ne 0 ]
do
case "$1" in
--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.'
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.