From 8349f0ff4872d71b52bc52c8a8b32596ee23202b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 22 Jun 2014 11:33:26 -0700 Subject: [PATCH 1/3] Make sure `nvm ls foo` returns a nonzero exit code when a version is not found. Fixes #440. --- nvm.sh | 6 ++++-- ...foo\" should return a nonzero exit code when not found" | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100755 "test/fast/Running \"nvm ls foo\" should return a nonzero exit code when not found" diff --git a/nvm.sh b/nvm.sh index 54a25f6..6354034 100644 --- a/nvm.sh +++ b/nvm.sh @@ -571,11 +571,13 @@ nvm() { NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@" ;; "ls" | "list" ) - nvm_print_versions "`nvm_ls $2`" + NVM_LS_OUTPUT=$(nvm_ls "$2") + NVM_LS_EXIT_CODE=$? + nvm_print_versions "$NVM_LS_OUTPUT" if [ $# -eq 1 ]; then nvm alias fi - return + return $NVM_LS_EXIT_CODE && $? ;; "ls-remote" | "list-remote" ) nvm_print_versions "`nvm_ls_remote $2`" diff --git "a/test/fast/Running \"nvm ls foo\" should return a nonzero exit code when not found" "b/test/fast/Running \"nvm ls foo\" should return a nonzero exit code when not found" new file mode 100755 index 0000000..b29a947 --- /dev/null +++ "b/test/fast/Running \"nvm ls foo\" should return a nonzero exit code when not found" @@ -0,0 +1,7 @@ + #!/bin/sh + +. ../../nvm.sh + +nvm ls nonexistent_version +[ "$?" = "3" ] + From 4b593bcda23314260880a1793e21c40b93908b5c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 22 Jun 2014 17:20:31 -0700 Subject: [PATCH 2/3] Make sure these vars are local, where supported --- nvm.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nvm.sh b/nvm.sh index 6354034..20c781a 100644 --- a/nvm.sh +++ b/nvm.sh @@ -571,6 +571,8 @@ nvm() { NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@" ;; "ls" | "list" ) + local NVM_LS_OUTPUT + local NVM_LS_EXIT_CODE NVM_LS_OUTPUT=$(nvm_ls "$2") NVM_LS_EXIT_CODE=$? nvm_print_versions "$NVM_LS_OUTPUT" From fb215546ee5041b4146c1d0806a0390a759845c5 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 26 Jun 2014 16:52:48 -0700 Subject: [PATCH 3/3] Don't bother trying to return the exit code of `nvm alias` or `nvm_print_versions` --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 20c781a..782a432 100644 --- a/nvm.sh +++ b/nvm.sh @@ -579,7 +579,7 @@ nvm() { if [ $# -eq 1 ]; then nvm alias fi - return $NVM_LS_EXIT_CODE && $? + return $NVM_LS_EXIT_CODE ;; "ls-remote" | "list-remote" ) nvm_print_versions "`nvm_ls_remote $2`"