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

[New] Support --no-progress for nvm install, close #1079 #1422

Merged
merged 1 commit into from
May 2, 2018

Conversation

PeterDaveHello
Copy link
Collaborator

@PeterDaveHello PeterDaveHello commented Mar 9, 2017

Fixes #1079

nvm.sh Outdated
local NODE_OR_IOJS
if [ "${FLAVOR}" = 'node' ]; then
NODE_OR_IOJS="${FLAVOR}"
fi
if [ "${NVM_NO_PROGRESS}" = "1" ]; then
Copy link

@samrocketman samrocketman Mar 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For things like this it's best to test if the environment variable is non-zero length:

if [ -n "${NVM_NO_PROGRESS}" ]; then
...
fi

Either 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
local NODE_OR_IOJS
if [ "${FLAVOR}" = 'node' ]; then
NODE_OR_IOJS="${FLAVOR}"
fi
if [ "${NVM_NO_PROGRESS}" = "1" ]; then
PROGRESS_BAR="-s"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@@ -78,7 +78,7 @@ nvm_download() {
ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \
-e 's/-L //' \
-e 's/-I /--server-response /' \
-e 's/-s /-q /' \
-e 's/-s /-nv -q /' \
Copy link

@samrocketman samrocketman Mar 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@@ -2458,7 +2469,7 @@ nvm() {
nvm_get_make_jobs
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to earlier comment:

if NVM_NO_PROGRESS="${NVM_NO_PROGRESS:-${noprogress}}" nvm_install_source ...

nvm.sh Outdated
@@ -2449,7 +2460,7 @@ nvm() {

# 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
Copy link

@samrocketman samrocketman Mar 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@PeterDaveHello
Copy link
Collaborator Author

@ljharb do you agree with all the change requests from @samrocketman? If so, I can start to update the PR, thanks.

@ljharb
Copy link
Member

ljharb commented Mar 17, 2017

@PeterDaveHello the comments look good; I'm confused why NVM_NO_PROGRESS can't just be "empty" or "nonempty" instead of a "noprogress" string?

nvm.sh Outdated
@@ -2273,8 +2279,9 @@ nvm() {
version_not_provided=1
fi

local nobinary
local nobinary noprogress
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put each local declaration on its own separate line.

@PeterDaveHello
Copy link
Collaborator Author

Okay I updated 😄

Copy link

@samrocketman samrocketman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks for taking the time.

@ljharb ljharb added feature requests I want a new feature in nvm! installing node Issues with installing node/io.js versions. labels Mar 18, 2017
@PeterDaveHello
Copy link
Collaborator Author

Got conflicts ... fixing now.

@PeterDaveHello PeterDaveHello force-pushed the no-progress-bar-support branch 2 times, most recently from 6873bf0 to 8195949 Compare March 19, 2017 08:44
@PeterDaveHello
Copy link
Collaborator Author

Should be fixed now.

@ljharb
Copy link
Member

ljharb commented Mar 20, 2017

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

@samrocketman
Copy link

@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

@PeterDaveHello
Copy link
Collaborator Author

My mistake, should be fixed now.

@ljharb
Copy link
Member

ljharb commented Mar 21, 2017

@samrocketman should be whatever comes stock on my Mac:

```sh $ lsb_release -a -bash: lsb_release: command not found

$ head -n1 /etc/issue
head: /etc/issue: No such file or directory

$ uname -rms
Darwin 16.4.0 x86_64

$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.

$ curl --version
curl 7.51.0 (x86_64-apple-darwin16.0) libcurl/7.51.0 SecureTransport zlib/1.2.8
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets

$ wget --version
GNU Wget 1.19.1 built on darwin15.6.0.

-cares +digest -gpgme +https +ipv6 -iri +large-file -metalink -nls
+ntlm +opie -psl +ssl/openssl

Wgetrc:
/usr/local/etc/wgetrc (system)
Compile:
clang -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/usr/local/etc/wgetrc"
-DLOCALEDIR="/usr/local/Cellar/wget/1.19.1/share/locale" -I.
-I../lib -I../lib -I/usr/local/opt/openssl/include -DNDEBUG
Link:
clang -DNDEBUG -liconv -L/usr/local/opt/openssl/lib -lssl -lcrypto
-ldl -lz ftp-opie.o openssl.o http-ntlm.o ../lib/libgnu.a

Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
http://www.gnu.org/licenses/gpl.html.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Originally written by Hrvoje Niksic hniksic@xemacs.org.
Please send bug reports and questions to bug-wget@gnu.org.

$ sed --version
sed: illegal option -- -

</details>

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@PeterDaveHello
Copy link
Collaborator Author

I'm not sure what kind of assertion would it looks like, any suggestions?

@ljharb
Copy link
Member

ljharb commented Mar 22, 2017

Take a look at test/fast/Unit tests/nvm_get_checksum and a number of other tests in that folder for inspiration.

@ljharb
Copy link
Member

ljharb commented Jun 13, 2017

@PeterDaveHello it'd be great to get this in soon; have you had a chance to work on these tests?

@PeterDaveHello
Copy link
Collaborator Author

@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?

@PeterDaveHello
Copy link
Collaborator Author

@ljharb please take a look, test added, not sure if it's good enough, thanks.

@PeterDaveHello PeterDaveHello force-pushed the no-progress-bar-support branch 2 times, most recently from df45148 to dd238c1 Compare April 23, 2018 11:07
@PeterDaveHello
Copy link
Collaborator Author

Ping... (merge conflicts fixed)

nvm.sh Outdated
local NODE_OR_IOJS
if [ "${FLAVOR}" = 'node' ]; then
NODE_OR_IOJS="${FLAVOR}"
fi
if [ "${NVM_NO_PROGRESS-}" = "1" ]; then
PROGRESS_BAR="-sS"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as both forms work on the same systems, I'd prefer the long versions for readability.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe revise this somewhere else? Consistency is important.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair. We can stick to the short versions now but please add the long ones in a comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, in that case let's stick with the short options (but comment the long ones, for clarity)

nvm.sh Outdated
if [ "${NVM_NO_PROGRESS-}" = "1" ]; then
PROGRESS_BAR="-sS"
else
PROGRESS_BAR="--progress-bar"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is "PROGRESS_BAR", as defined here, referenced?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the definition?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no - I mean that lines 2017-2021 seem useless since nothing ever uses PROGRESS_BAR in this code path.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nvm_download_artifact() will use it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't use it unless it's passed or exported.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm ... shell's variable passing is always confusing, it looks working. I pass it anyway ;)

@PeterDaveHello PeterDaveHello force-pushed the no-progress-bar-support branch 4 times, most recently from 5d118ce to d9afdba Compare April 25, 2018 04:21
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try this out locally, then merge.

@ljharb ljharb merged commit 113d807 into nvm-sh:master May 2, 2018
@PeterDaveHello PeterDaveHello deleted the no-progress-bar-support branch May 2, 2018 04:36
@samrocketman
Copy link

Thanks for sticking it out @PeterDaveHello

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature requests I want a new feature in nvm! installing node Issues with installing node/io.js versions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants