[New] `nvm ls`: add `--no-alias` to suppress alias output
Per https://github.com/creationix/nvm/issues/1792#issuecomment-466696504
diff --git a/.editorconfig b/.editorconfig
index ea25d86..c1b7c13 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -15,5 +15,8 @@
[test/fast/Listing versions/Running "nvm ls" calls into nvm_alias]
indent_size = false
+[test/fast/Listing versions/Running "nvm ls --no-alias" does not call into nvm_alias]
+indent_size = false
+
[Makefile]
indent_style = tab
diff --git a/nvm.sh b/nvm.sh
index 0dcd274..52aba8a 100644
--- a/nvm.sh
+++ b/nvm.sh
@@ -3138,10 +3138,12 @@
"ls" | "list")
local PATTERN
local NVM_NO_COLORS
+ local NVM_NO_ALIAS
while [ $# -gt 0 ]; do
case "${1}" in
--) ;;
--no-colors) NVM_NO_COLORS="${1}" ;;
+ --no-alias) NVM_NO_ALIAS="${1}" ;;
--*)
nvm_err "Unsupported option \"${1}\"."
return 55
@@ -3152,12 +3154,16 @@
esac
shift
done
+ if [ -n "${PATTERN-}" ] && [ -n "${NVM_NO_ALIAS}" ]; then
+ nvm_err '`--no-alias` is not supported when a pattern is provided.'
+ return 55
+ fi
local NVM_LS_OUTPUT
local NVM_LS_EXIT_CODE
NVM_LS_OUTPUT=$(nvm_ls "${PATTERN-}")
NVM_LS_EXIT_CODE=$?
NVM_NO_COLORS="${NVM_NO_COLORS-}" nvm_print_versions "${NVM_LS_OUTPUT}"
- if [ -z "${PATTERN-}" ]; then
+ if [ -z "${NVM_NO_ALIAS-}" ] && [ -z "${PATTERN-}" ]; then
if [ -n "${NVM_NO_COLORS-}" ]; then
nvm alias --no-colors
else
diff --git "a/test/fast/Listing versions/Running \"nvm ls --no-alias\" does not call into nvm_alias" "b/test/fast/Listing versions/Running \"nvm ls --no-alias\" does not call into nvm_alias"
new file mode 100755
index 0000000..20e28ec
--- /dev/null
+++ "b/test/fast/Listing versions/Running \"nvm ls --no-alias\" does not call into nvm_alias"
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+\. ../../../nvm.sh
+\. ../../common.sh
+
+die () { echo "$@" ; unset -f nvm_ls nvm_list_aliases; exit 1; }
+
+make_fake_node v0.12.87 || die 'fake v0.12.87 could not be made'
+make_fake_node v0.12.9 || die 'fake v0.12.9 could not be made'
+make_fake_iojs v0.1.2 || die 'fake iojs-v0.1.2 could not be made'
+make_fake_iojs v0.10.2 || die 'fake iojs-v0.10.2 could not be made'
+
+set -e
+
+nvm_list_aliases() {
+ echo 'sd-6'
+}
+# sanity check
+OUTPUT="$(nvm alias)"
+EXPECTED_OUTPUT='sd-6'
+[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "1: expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
+
+nvm_ls() {
+ echo v0.12.87
+ echo v0.12.9
+ echo iojs-v0.1.2
+ echo iojs-v0.10.2
+}
+OUTPUT="$(nvm ls --no-colors --no-alias)"
+EXPECTED_OUTPUT=" v0.12.87 *
+ v0.12.9 *
+ iojs-v0.1.2 *
+ iojs-v0.10.2 *"
+[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "2: expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
diff --git "a/test/fast/Listing versions/Running \"nvm ls --no-alias\" with a pattern errors" "b/test/fast/Listing versions/Running \"nvm ls --no-alias\" with a pattern errors"
new file mode 100755
index 0000000..6f5a809
--- /dev/null
+++ "b/test/fast/Listing versions/Running \"nvm ls --no-alias\" with a pattern errors"
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+\. ../../../nvm.sh
+\. ../../common.sh
+
+die () { echo "$@" ; unset -f nvm_ls nvm_list_aliases; exit 1; }
+
+set -e
+
+OUTPUT="$(nvm ls --no-colors --no-alias pattern 2>&1 ||:)"
+EXPECTED_OUTPUT='`--no-alias` is not supported when a pattern is provided.'
+EXIT_CODE="$(nvm ls --no-colors --no-alias pattern >/dev/null 2>&1 || echo $?)"
+[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
+
+[ "${EXIT_CODE}" = 55 ] || die "expected 55; got >${EXIT_CODE}<"