Skip to content
Myr

[New] Supercharge `nvm debug` output

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Try to get shell version, OS and its version, curl/wget/git version.

authored by Peter Dave Hello · committed by Jordan Harband · parent f344d06 · Browse files · 2 files+81 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+81 added−1 removed

  • tests:+40 added−0 removed
  • other:+41 added−1 removed

2 files+81 added−1 removed

added:test/fast/Unit tests/nvm_command_info+40 added
1#!/bin/sh23cleanup() {4 unalias wget5 unset -f wget6 unset WGET_EXPECTED_INFO WGET_COMMAND_INFO7}89die() { echo "$@" ; cleanup ; exit 1; }1011\. ../../../nvm.sh121314# 1. test wget command15WGET_COMMAND_INFO="$(nvm_command_info wget)"16WGET_EXPECTED_INFO="$(which wget)"17[ "${WGET_COMMAND_INFO}" = "${WGET_EXPECTED_INFO}" ] || die "wget command info wrong(stage 1), expected: '${WGET_EXPECTED_INFO}', got '${WGET_COMMAND_INFO}'"1819cleanup2021# 2. test aliased wget22shopt -s expand_aliases23# enable expand_aliases to make alias working in interactive shell24alias wget="wget -V"25WGET_COMMAND_INFO="$(nvm_command_info wget)"26WGET_EXPECTED_INFO="$(which wget) (wget -V)"27[ "${WGET_COMMAND_INFO}" = "${WGET_EXPECTED_INFO}" ] || die "wget command info wrong(stage 2), expected: '${WGET_EXPECTED_INFO}', got '${WGET_COMMAND_INFO}'"2829cleanup3031# 3. test wget function32wget() {33 echo "wget function"34}3536WGET_COMMAND_INFO="$(nvm_command_info wget)"37WGET_EXPECTED_INFO="$(type wget)"38[ "${WGET_COMMAND_INFO}" = "${WGET_EXPECTED_INFO}" ] || die "wget command info wrong(stage 3), expected: '${WGET_EXPECTED_INFO}', got '${WGET_COMMAND_INFO}'"3940cleanup
modified:nvm.sh+41 added-1 removed
47 unmodified lines
48 # shellcheck disable=SC100149 \alias "${1-}" > /dev/null 2>&150}5152nvm_command_info() {53 local COMMAND54 local INFO55 COMMAND="${1}"56 if type "${COMMAND}" | command grep -q hashed; then57 INFO="$(type "${COMMAND}" | command sed -E 's/\(|)//g' | command awk '{print $4}')"58 elif type "${COMMAND}" | command grep -q aliased; then59 INFO="$(which "${COMMAND}") ($(type "${COMMAND}" | command awk '{ $1=$2=$3=$4="" ;print }' | command sed -e 's/^\ *//g' -Ee "s/\`|'//g" ))"60 elif type "${COMMAND}" | command grep -q "^${COMMAND} is an alias for"; then61 INFO="$(which "${COMMAND}") ($(type "${COMMAND}" | command awk '{ $1=$2=$3=$4=$5="" ;print }' | command sed 's/^\ *//g'))"62 elif type "${COMMAND}" | command grep -q "^${COMMAND} is \/"; then63 INFO="$(type "${COMMAND}" | command awk '{print $3}')"64 else65 INFO="$(type "${COMMAND}")"66 fi67 nvm_echo "${INFO}"68}6970nvm_has_colors() {71 local NVM_COLORS72 if nvm_has tput; then73 NVM_COLORS="$(tput -T "${TERM:-vt100}" colors)"
2192 unmodified lines
2266 nvm_err "\$PREFIX: '$(nvm_sanitize_path "$PREFIX")'"2267 nvm_err "\$NPM_CONFIG_PREFIX: '$(nvm_sanitize_path "$NPM_CONFIG_PREFIX")'"2268 nvm_err "\$NVM_NODEJS_ORG_MIRROR: '${NVM_NODEJS_ORG_MIRROR}'"2269 nvm_err "\$NVM_IOJS_ORG_MIRROR: '${NVM_IOJS_ORG_MIRROR}'"2270 nvm_err "shell version: '$(${SHELL} --version | command head -n 1)'"2271 nvm_err "uname -a: '$(uname -a | awk '{$2=""; print}' | xargs)'"2272 if [ "$(nvm_get_os)" = "darwin" ] && nvm_has sw_vers; then2273 nvm_err "OS version: $(sw_vers | command awk '{print $2}' | command xargs)"2274 elif [ -r "/etc/issue" ]; then2275 nvm_err "OS version: $(command head -n 1 /etc/issue | command sed 's/\\.//g')"2276 fi2277 if nvm_has "curl"; then2278 nvm_err "curl: $(nvm_command_info curl), $(command curl -V | command head -n 1)"2279 else2280 nvm_err "curl: not found"2281 fi2282 if nvm_has "wget"; then2283 nvm_err "wget: $(nvm_command_info wget), $(command wget -V | command head -n 1)"2284 else2285 nvm_err "wget: not found"2286 fi2287 if nvm_has "git"; then2288 nvm_err "git: $(nvm_command_info git), $(command git --version)"2289 else2290 nvm_err "git: not found"2291 fi2292 local NVM_DEBUG_OUTPUT2293 for NVM_DEBUG_COMMAND in 'nvm current' 'which node' 'which iojs' 'which npm' 'npm config get prefix' 'npm root -g'2294 do2295 NVM_DEBUG_OUTPUT="$($NVM_DEBUG_COMMAND 2>&1)"
947 unmodified lines
3243 nvm_list_aliases nvm_make_alias nvm_print_alias_path \3244 nvm_print_default_alias nvm_print_formatted_alias nvm_resolve_local_alias \3245 nvm_sanitize_path nvm_has_colors nvm_process_parameters \3246 node_version_has_solaris_binary iojs_version_has_solaris_binary \3207 nvm_curl_libz_support \3247 nvm_curl_libz_support nvm_command_info \3248 > /dev/null 2>&13249 unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \3250 NVM_CD_FLAGS NVM_BIN NVM_MAKE_JOBS \3251 > /dev/null 2>&1
92 unmodified lines