Skip to content
Myr

[Refactor] Add `nvm_has_non_aliased`

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

authored by Peter Dave Hello · committed by Jordan Harband · parent 316c9f3 · Browse files · 2 files+56 added−28 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+56 added−28 removed

  • tests:+24 added−0 removed
  • other:+32 added−28 removed

2 files+56 added−28 removed

added:test/fast/Unit tests/nvm_has_non_aliased+24 added
1#!/bin/sh23cleanup () { unalias foo; unalias grep; }4die () { echo "$@" ; cleanup ; exit 1; }56\. ../../../nvm.sh78alias foo='bar'9! nvm_has_non_aliased foo || die '"nvm_has_non_aliased foo" was not true'1011alias grep='grep'12unalias grep || die '"unalias grep" failed'13nvm_has_non_aliased grep || die '"nvm_has_non_aliased grep" with unaliased grep was not false'1415alias grep='grep'16! nvm_has_non_aliased grep || die '"nvm_is_alias grep" with aliased grep was not true'1718nvm_has_non_aliased cat && type cat > /dev/null || die 'nvm_has_non_aliased locates "cat" properly'1920[ "~$(nvm_has_non_aliased foobarbaz 2>&1)" = "~" ] || die "nvm_has_non_aliased does not suppress error output"2122! nvm_has_non_aliased foobarbaz && ! type foobarbaz >/dev/null 2>&1 || die "nvm_has_non_aliased does not return a nonzero exit code when not found"2324cleanup
modified:nvm.sh+32 added-28 removed
37 unmodified lines
38nvm_has() {39 type "${1-}" > /dev/null 2>&140}4142nvm_has_non_aliased() {43 nvm_has "${1-}" && ! nvm_is_alias "${1-}"44}4546nvm_is_alias() {47 # this is intentionally not "command alias" so it works in zsh.48 # shellcheck disable=SC100149 \alias "${1-}" > /dev/null 2>&1
1012 unmodified lines
1062 nvm_echo "${VERSIONS}"1063}10641065nvm_get_checksum_alg() {1062 if nvm_has "sha256sum" && ! nvm_is_alias "sha256sum"; then1066 if nvm_has_non_aliased "sha256sum"; then1067 nvm_echo 'sha-256'1064 elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then1068 elif nvm_has_non_aliased "shasum"; then1069 nvm_echo 'sha-256'1066 elif nvm_has "sha256" && ! nvm_is_alias "sha256"; then1070 elif nvm_has_non_aliased "sha256"; then1071 nvm_echo 'sha-256'1068 elif nvm_has "gsha256sum" && ! nvm_is_alias "gsha256sum"; then1072 elif nvm_has_non_aliased "gsha256sum"; then1073 nvm_echo 'sha-256'1070 elif nvm_has "openssl" && ! nvm_is_alias "openssl"; then1074 elif nvm_has_non_aliased "openssl"; then1075 nvm_echo 'sha-256'1072 elif nvm_has "bssl" && ! nvm_is_alias "bssl"; then1076 elif nvm_has_non_aliased "bssl"; then1077 nvm_echo 'sha-256'1074 elif nvm_has "sha1sum" && ! nvm_is_alias "sha1sum"; then1078 elif nvm_has_non_aliased "sha1sum"; then1079 nvm_echo 'sha-1'1076 elif nvm_has "sha1" && ! nvm_is_alias "sha1"; then1080 elif nvm_has_non_aliased "sha1"; then1081 nvm_echo 'sha-1'1078 elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then1082 elif nvm_has_non_aliased "shasum"; then1083 nvm_echo 'sha-1'1084 else1085 nvm_err 'Unaliased sha256sum, shasum, sha256, gsha256sum, openssl, or bssl not found.'1086 nvm_err 'Unaliased sha1sum, sha1, or shasum not found.'
11 unmodified lines
1098 nvm_err 'Provided file to checksum does not exist.'1099 return 11100 fi11011098 if nvm_has "sha256sum" && ! nvm_is_alias "sha256sum"; then1102 if nvm_has_non_aliased "sha256sum"; then1103 nvm_err 'Computing checksum with sha256sum'1104 command sha256sum "${FILE}" | command awk '{print $1}'1101 elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then1105 elif nvm_has_non_aliased "shasum"; then1106 nvm_err 'Computing checksum with shasum -a 256'1107 command shasum -a 256 "${FILE}" | command awk '{print $1}'1104 elif nvm_has "sha256" && ! nvm_is_alias "sha256"; then1108 elif nvm_has_non_aliased "sha256"; then1109 nvm_err 'Computing checksum with sha256 -q'1110 command sha256 -q "${FILE}" | command awk '{print $1}'1107 elif nvm_has "gsha256sum" && ! nvm_is_alias "gsha256sum"; then1111 elif nvm_has_non_aliased "gsha256sum"; then1112 nvm_err 'Computing checksum with gsha256sum'1113 command gsha256sum "${FILE}" | command awk '{print $1}'1110 elif nvm_has "openssl" && ! nvm_is_alias "openssl"; then1114 elif nvm_has_non_aliased "openssl"; then1115 nvm_err 'Computing checksum with openssl dgst -sha256'1116 command openssl dgst -sha256 "${FILE}" | command awk '{print $NF}'1113 elif nvm_has "bssl" && ! nvm_is_alias "bssl"; then1117 elif nvm_has_non_aliased "bssl"; then1118 nvm_err 'Computing checksum with bssl sha256sum'1119 command bssl sha256sum "${FILE}" | command awk '{print $1}'1116 elif nvm_has "sha1sum" && ! nvm_is_alias "sha1sum"; then1120 elif nvm_has_non_aliased "sha1sum"; then1121 nvm_err 'Computing checksum with sha1sum'1122 command sha1sum "${FILE}" | command awk '{print $1}'1119 elif nvm_has "sha1" && ! nvm_is_alias "sha1"; then1123 elif nvm_has_non_aliased "sha1"; then1124 nvm_err 'Computing checksum with sha1 -q'1125 command sha1 -q "${FILE}"1122 elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then1126 elif nvm_has_non_aliased "shasum"; then1127 nvm_err 'Computing checksum with shasum'1128 command shasum "${FILE}" | command awk '{print $1}'1129 fi1130}
59 unmodified lines
11901191nvm_checksum() {1192 local NVM_CHECKSUM1193 if [ -z "${3-}" ] || [ "${3-}" = 'sha1' ]; then1190 if nvm_has "sha1sum" && ! nvm_is_alias "sha1sum"; then1194 if nvm_has_non_aliased "sha1sum"; then1195 NVM_CHECKSUM="$(command sha1sum "${1-}" | command awk '{print $1}')"1192 elif nvm_has "sha1" && ! nvm_is_alias "sha1"; then1196 elif nvm_has_non_aliased "sha1"; then1197 NVM_CHECKSUM="$(command sha1 -q "${1-}")"1194 elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then1198 elif nvm_has_non_aliased "shasum"; then1199 NVM_CHECKSUM="$(command shasum "${1-}" | command awk '{print $1}')"1200 else1201 nvm_err 'Unaliased sha1sum, sha1, or shasum not found.'1202 return 21203 fi1204 else1201 if nvm_has "sha256sum" && ! nvm_is_alias "sha256sum"; then1205 if nvm_has_non_aliased "sha256sum"; then1206 NVM_CHECKSUM="$(command sha256sum "${1-}" | command awk '{print $1}')"1203 elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then1207 elif nvm_has_non_aliased "shasum"; then1208 NVM_CHECKSUM="$(command shasum -a 256 "${1-}" | command awk '{print $1}')"1205 elif nvm_has "sha256" && ! nvm_is_alias "sha256"; then1209 elif nvm_has_non_aliased "sha256"; then1210 NVM_CHECKSUM="$(command sha256 -q "${1-}" | command awk '{print $1}')"1207 elif nvm_has "gsha256sum" && ! nvm_is_alias "gsha256sum"; then1211 elif nvm_has_non_aliased "gsha256sum"; then1212 NVM_CHECKSUM="$(command gsha256sum "${1-}" | command awk '{print $1}')"1209 elif nvm_has "openssl" && ! nvm_is_alias "openssl"; then1213 elif nvm_has_non_aliased "openssl"; then1214 NVM_CHECKSUM="$(command openssl dgst -sha256 "${1-}" | command awk '{print $NF}')"1211 elif nvm_has "bssl" && ! nvm_is_alias "bssl"; then1215 elif nvm_has_non_aliased "bssl"; then1216 NVM_CHECKSUM="$(command bssl sha256sum "${1-}" | command awk '{print $1}')"1217 else1218 nvm_err 'Unaliased sha256sum, shasum, sha256, gsha256sum, openssl, or bssl not found.'1219 nvm_err 'WARNING: Continuing *without checksum verification*'
1939 unmodified lines
3159 nvm deactivate >/dev/null 2>&13160 unset -f nvm \3161 nvm_iojs_prefix nvm_node_prefix \3162 nvm_add_iojs_prefix nvm_strip_iojs_prefix \3159 nvm_is_iojs_version nvm_is_alias \3163 nvm_is_iojs_version nvm_is_alias nvm_has_non_aliased \3164 nvm_ls_remote nvm_ls_remote_iojs nvm_ls_remote_index_tab \3165 nvm_ls nvm_remote_version nvm_remote_versions \3166 nvm_install_binary nvm_clang_version \3167 nvm_get_mirror nvm_get_download_slug nvm_download_artifact \
122 unmodified lines