[New] Support --no-progress for nvm install, close #1079#1422
[New] Support --no-progress for nvm install, close #1079#1422ljharb merged 1 commit intonvm-sh:masterfrom
--no-progress for nvm install, close #1079#1422Conversation
nvm.sh
Outdated
| if [ "${FLAVOR}" = 'node' ]; then | ||
| NODE_OR_IOJS="${FLAVOR}" | ||
| fi | ||
| if [ "${NVM_NO_PROGRESS}" = "1" ]; then |
There was a problem hiding this comment.
For things like this it's best to test if the environment variable is non-zero length:
if [ -n "${NVM_NO_PROGRESS}" ]; then
...
fiEither it exists and has content or doesn't is how I've seen it typically tested in other projects which are bash-based. I tend to like that style of testing more.
nvm.sh
Outdated
| NODE_OR_IOJS="${FLAVOR}" | ||
| fi | ||
| if [ "${NVM_NO_PROGRESS}" = "1" ]; then | ||
| PROGRESS_BAR="-s" |
There was a problem hiding this comment.
Please use:
PROGRESS_BAR="-sS"-s by itself silences all output (including errors). However, I believe a user would want to know why something failed so -S will still properly surface errors to them. -sS will only output if there's an error.
nvm.sh
Outdated
| -e 's/-L //' \ | ||
| -e 's/-I /--server-response /' \ | ||
| -e 's/-s /-q /' \ | ||
| -e 's/-s /-nv -q /' \ |
There was a problem hiding this comment.
Related to other feedback I think this should be (adding -sS and excluding -q):
...
-e 's/-sS /-nv /'
...You don't want -q because it will completely disable output including errors. From the wget man page -nv is non-verbose but will still display errors when they occur (akin to -sS).
nvm.sh
Outdated
| fi | ||
|
|
||
| if nvm_install_source "${FLAVOR}" std "${VERSION}" "${NVM_MAKE_JOBS}" "${ADDITIONAL_PARAMETERS}"; then | ||
| if NVM_NO_PROGRESS="${noprogress}" nvm_install_source "${FLAVOR}" std "${VERSION}" "${NVM_MAKE_JOBS}" "${ADDITIONAL_PARAMETERS}"; then |
There was a problem hiding this comment.
Similar to earlier comment:
if NVM_NO_PROGRESS="${NVM_NO_PROGRESS:-${noprogress}}" nvm_install_source ...
nvm.sh
Outdated
| # skip binary install if "nobinary" option specified. | ||
| if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then | ||
| if nvm_install_binary "${FLAVOR}" std "${VERSION}"; then | ||
| if NVM_NO_PROGRESS="${noprogress}" nvm_install_binary "${FLAVOR}" std "${VERSION}"; then |
There was a problem hiding this comment.
Might I make a recommendation here as well?
if NVM_NO_PROGRESS="${NVM_NO_PROGRESS:-${noprogress}}" nvm_install_source ...If you look up Parameter Expansion in the bash man page you'll find that ${VAR:-default} will only take the default value if $VAR is unset. The reason why this is useful is because it allows a user to set NVM_NO_PROGRESS globally as an environment variable on their system which will always disable progress without having to use the nvm --no-progress option. In a CI-like, environment I feel this would be desirable.
Just my two cents on environment variables and using defaults.
|
@ljharb do you agree with all the change requests from @samrocketman? If so, I can start to update the PR, thanks. |
|
@PeterDaveHello the comments look good; I'm confused why |
nvm.sh
Outdated
| fi | ||
|
|
||
| local nobinary | ||
| local nobinary noprogress |
There was a problem hiding this comment.
please put each local declaration on its own separate line.
1eee505 to
dc35687
Compare
|
Okay I updated 😄 |
samrocketman
left a comment
There was a problem hiding this comment.
Looks good to me. Thanks for taking the time.
dc35687 to
f0689cf
Compare
|
Got conflicts ... fixing now. |
6873bf0 to
8195949
Compare
|
Should be fixed now. |
|
This doesn't seem to work for me consistently in local testing. nvm install --no-progress -s 5.9.0
Downloading https://nodejs.org/dist/v5.9.0/node-v5.9.0.tar.xz...
curl: (3) <url> malformed
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
1 12.6M 1 211k 0 0 355k 0 0:00:36 --:--:-- 0:00:36 354k^C |
|
@ljharb can you elaborate on the versions of software you're using? Considering what is involved in this PR perhaps versions of: lsb_release -a
#alternatively instead of lsb_release: head -n1 /etc/issue
uname -rms
bash --version
curl --version
wget --version
sed --version |
8195949 to
ddb0a92
Compare
|
My mistake, should be fixed now. |
|
@samrocketman should be whatever comes stock on my Mac: Details```sh $ lsb_release -a -bash: lsb_release: command not found$ head -n1 /etc/issue $ uname -rms $ bash --version $ curl --version $ wget --version -cares +digest -gpgme +https +ipv6 -iri +large-file -metalink -nls Wgetrc: Copyright (C) 2015 Free Software Foundation, Inc. Originally written by Hrvoje Niksic hniksic@xemacs.org. $ sed --version |
ljharb
left a comment
There was a problem hiding this comment.
This now appears to work in my local testing, thanks.
Is there any way we could test this? Perhaps one test could mock out nvm_download and assert on the presence of --progress-bar vs -sS, and then another test for nvm_download itself?
|
I'm not sure what kind of assertion would it looks like, any suggestions? |
|
Take a look at |
|
@PeterDaveHello it'd be great to get this in soon; have you had a chance to work on these tests? |
|
@ljharb sorry for the delay, I'd like to, but not sure when can I finish it, no offense, but I also wonder if it's a little bit rush, would that be possible that you can directly finish the tests? |
ddb0a92 to
4d5b180
Compare
|
@ljharb please take a look, test added, not sure if it's good enough, thanks. |
df45148 to
dd238c1
Compare
dd238c1 to
3b3e368
Compare
|
Ping... (merge conflicts fixed) |
| NODE_OR_IOJS="${FLAVOR}" | ||
| fi | ||
| if [ "${NVM_NO_PROGRESS-}" = "1" ]; then | ||
| PROGRESS_BAR="-sS" |
There was a problem hiding this comment.
should this be --silent --show-error, or would that make combining them tricky?
Is there a reason we ever don't want --show-error semantics?
There was a problem hiding this comment.
I think it's because we use parameters like -L, -I, -C, so it's to maintain consistency to use a short parameter and maybe I should even use -# instead of --progress-bar?
There was a problem hiding this comment.
As long as both forms work on the same systems, I'd prefer the long versions for readability.
There was a problem hiding this comment.
Maybe revise this somewhere else? Consistency is important.
There was a problem hiding this comment.
Fair. We can stick to the short versions now but please add the long ones in a comment.
There was a problem hiding this comment.
I mentioned this before (can't remember where). The long option is not always available in some versions of curl. However, the short option definitely is. For compatibility, I recommend sticking to the short option for this specific feature.
There was a problem hiding this comment.
Thanks, in that case let's stick with the short options (but comment the long ones, for clarity)
| if [ "${NVM_NO_PROGRESS-}" = "1" ]; then | ||
| PROGRESS_BAR="-sS" | ||
| else | ||
| PROGRESS_BAR="--progress-bar" |
There was a problem hiding this comment.
where is "PROGRESS_BAR", as defined here, referenced?
There was a problem hiding this comment.
You mean the definition?
There was a problem hiding this comment.
no - I mean that lines 2017-2021 seem useless since nothing ever uses PROGRESS_BAR in this code path.
There was a problem hiding this comment.
I think nvm_download_artifact() will use it
There was a problem hiding this comment.
It can't use it unless it's passed or exported.
There was a problem hiding this comment.
hmmm ... shell's variable passing is always confusing, it looks working. I pass it anyway ;)
5d118ce to
d9afdba
Compare
ljharb
left a comment
There was a problem hiding this comment.
I'll try this out locally, then merge.
d9afdba to
113d807
Compare
|
Thanks for sticking it out @PeterDaveHello |
Fixes #1079