Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix exit-code pass-thru with `nave use` and add -o option to enable overriding default cURL flags #38

Closed
wants to merge 5 commits into from

2 participants

@niallo

E.g. get silent output with

nave -o'-Lfs' install 0.8.0

niallo added some commits
@niallo niallo support override default cURL options (-#Lf) via new, options -o flag.
E.g.

nave -o '-Ls' ls-remote
4b9f805
@niallo niallo options parsing 14751bb
@niallo niallo bump version d8c73ff
@niallo niallo correctly pass-thu exit status with `nave use`.
e.g without patch:

<nialljohiggins@mbp:nave>$ nave use 0.8.0 exit 1
Already installed: 0.8.0
using 0.8.0
<nialljohiggins@mbp:nave>$ echo $?
0

with patch:

<nialljohiggins@mbp:nave>$ sh nave.sh use 0.8.0 exit 1
Already installed: 0.8.0
using 0.8.0
failed somehow
<nialljohiggins@mbp:nave>$ echo $?
1
5fdb247
@niallo

Added another commit to fix bug with nave use:

without patch:

$ nave use 0.8.0 exit 1
Already installed: 0.8.0
using 0.8.0
$ echo $?
0

with patch:

$ sh nave.sh use 0.8.0 exit 1
Already installed: 0.8.0
using 0.8.0
failed somehow
$ echo $?
1

@isaacs
Owner

Took the return value hiding, and changed to not do --debug.

Parsing options and overriding the curl opts seems weird and unnecessary to me.

In general, it's best to only have one feature per pull request. You can push different features to different branches to keep it more clear.

@isaacs isaacs closed this
@niallo

Thanks. Sorry about the multiple features in that pull request, will do branches next time.

Re: cURL opts. My use case is saving nave output. cURL's progress bar (-# option) does not gracefully handle non-TTY output fd and essentially spews garbage. To see what I mean, just redirect nave output to a file. Hopefully that convinces you :-)

Perhaps a better alternative to parsing options is using an environment variable? I'm not wedded to the getopt approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 25, 2012
  1. @niallo

    support override default cURL options (-#Lf) via new, options -o flag.

    niallo authored
    E.g.
    
    nave -o '-Ls' ls-remote
  2. @niallo

    options parsing

    niallo authored
  3. @niallo

    bump version

    niallo authored
Commits on Jun 27, 2012
  1. @niallo

    correctly pass-thu exit status with `nave use`.

    niallo authored
    e.g without patch:
    
    <nialljohiggins@mbp:nave>$ nave use 0.8.0 exit 1
    Already installed: 0.8.0
    using 0.8.0
    <nialljohiggins@mbp:nave>$ echo $?
    0
    
    with patch:
    
    <nialljohiggins@mbp:nave>$ sh nave.sh use 0.8.0 exit 1
    Already installed: 0.8.0
    using 0.8.0
    failed somehow
    <nialljohiggins@mbp:nave>$ echo $?
    1
Commits on Jul 17, 2012
  1. @niallo
This page is out of date. Refresh to see the latest.
Showing with 38 additions and 6 deletions.
  1. +5 −1 README.md
  2. +32 −4 nave.sh
  3. +1 −1  package.json
View
6 README.md
@@ -10,7 +10,11 @@ from here, or symlink it wherever you want.
## Usage
- Usage: nave <cmd>
+ Usage: nave [-o curl options] <cmd>
+
+ Options:
+
+ -o options Override default cURL options (-#Lf)
Commands:
View
36 nave.sh
@@ -33,7 +33,29 @@ shopt -s extglob
tar=${TAR-tar}
+NAVE_CURL_OPTS="-#Lf"
+
main () {
+ # Parse options via getopt(1)
+ args=`getopt o: $*`
+ if [ $? -ne 0 ]
+ then
+ nave_help
+ exit 2
+ fi
+
+ set -- $args
+ while [ $# -ge 0 ]
+ do
+ case "$1"
+ in
+ -o)
+ NAVE_CURL_OPTS="$2"; shift; shift;;
+ --)
+ shift; break;;
+ esac
+ done
+
local SELF_PATH DIR SYM
# get the absolute path of the executable
SELF_PATH="$0"
@@ -165,7 +187,7 @@ nave_fetch () {
"http://nodejs.org/dist/node-$version.tar.gz"
)
for url in "${urls[@]}"; do
- curl -#Lf "$url" > "$src".tgz
+ curl $NAVE_CURL_OPTS "$url" > "$src".tgz
if [ $? -eq 0 ]; then
$tar xzf "$src".tgz -C "$src" --strip-components=1
if [ $? -eq 0 ]; then
@@ -190,7 +212,7 @@ build () {
( cd -- "$src"
[ -f ~/.naverc ] && . ~/.naverc || true
- if [ "$NAVE_CONFIG" == "" ]; then
+ if [ "$NAVE_CONFIG" == "--debug" ]; then
NAVE_CONFIG=("--debug")
fi
JOBS=$jobs ./configure "${NAVE_CONFIG[@]}" --prefix="$2" \
@@ -402,6 +424,7 @@ nave_use () {
NODE_PATH="$lib" \
NAVE_LOGIN="" \
"$BASH" -c ". $(enquote_all $NAVE_DIR/naverc); $(enquote_all "$@")"
+ exit_code=$?
hash -r
else
hash -r
@@ -415,9 +438,10 @@ nave_use () {
NODE_PATH="$lib" \
NAVE_LOGIN="1" \
"$BASH" --rcfile "$NAVE_DIR/naverc"
+ exit_code=$?
hash -r
fi
- return $?
+ return $exit_code
}
nave_named () {
@@ -519,7 +543,11 @@ nave_uninstall () {
nave_help () {
cat <<EOF
-Usage: nave <cmd>
+Usage: nave [-o curl options] <cmd>
+
+Options:
+
+-o options Override default cURL options (-#Lf)
Commands:
View
2  package.json
@@ -1,7 +1,7 @@
{ "name" : "nave"
, "author" : "Isaac Z. Schlueter <i@izs.me>"
, "description" : "Virtual Environments for Node"
-, "version" : "0.2.13"
+, "version" : "0.2.14"
, "preferGlobal" : true
, "bin" : { "nave" : "./nave.sh" }
, "LICENSE": "BSD"
Something went wrong with that request. Please try again.