Skip to content

Commit

Permalink
Clean up nvm ls-remote behavior when one of node/iojs reports N/A.
Browse files Browse the repository at this point in the history
This change:
 - removes a superfluous N/A
 - fixes the exit code to return 0 unless no version is found
 - enables `nvm install v1` and similar patterns.
  • Loading branch information
ljharb committed Jan 20, 2015
1 parent f1f11e3 commit ea12784
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1309,23 +1309,32 @@ nvm() {

local NVM_LS_REMOTE_EXIT_CODE
NVM_LS_REMOTE_EXIT_CODE=0
local NVM_LS_REMOTE_OUTPUT
NVM_LS_REMOTE_OUTPUT=''
if [ "_$NVM_FLAVOR" != "_$(nvm_iojs_prefix)" ]; then
local NVM_LS_REMOTE_OUTPUT
NVM_LS_REMOTE_OUTPUT=$(nvm_ls_remote "$PATTERN")
NVM_LS_REMOTE_EXIT_CODE=$?
nvm_print_versions "$NVM_LS_REMOTE_OUTPUT"
fi

local NVM_LS_REMOTE_IOJS_EXIT_CODE
NVM_LS_REMOTE_IOJS_EXIT_CODE=0
local NVM_LS_REMOTE_IOJS_OUTPUT
NVM_LS_REMOTE_IOJS_OUTPUT=''
if [ "_$NVM_FLAVOR" != "_$(nvm_node_prefix)" ]; then
local NVM_LS_REMOTE_IOJS_OUTPUT
NVM_LS_REMOTE_IOJS_OUTPUT=$(nvm_ls_remote_iojs "$PATTERN")
NVM_LS_REMOTE_IOJS_EXIT_CODE=$?
nvm_print_versions "$NVM_LS_REMOTE_IOJS_OUTPUT"
fi

return $NVM_LS_REMOTE_EXIT_CODE && $NVM_LS_REMOTE_IOJS_EXIT_CODE
local NVM_OUTPUT
NVM_OUTPUT="$(echo "$NVM_LS_REMOTE_OUTPUT
$NVM_LS_REMOTE_IOJS_OUTPUT" | grep -v "N/A" | sed '/^$/d')"
if [ -n "$NVM_OUTPUT" ]; then
nvm_print_versions "$NVM_OUTPUT"
return $NVM_LS_REMOTE_EXIT_CODE || $NVM_LS_REMOTE_IOJS_EXIT_CODE
else
nvm_print_versions "N/A"
return 3
fi
;;
"current" )
nvm_version current
Expand Down

0 comments on commit ea12784

Please sign in to comment.