[New] `nvm ls`: add `--no-alias` to suppress alias output
Per https://github.com/creationix/nvm/issues/1792#issuecomment-466696504
parent
04fdb2331b
commit
c6740f5a6e
|
@ -15,5 +15,8 @@ indent_size = false
|
||||||
[test/fast/Listing versions/Running "nvm ls" calls into nvm_alias]
|
[test/fast/Listing versions/Running "nvm ls" calls into nvm_alias]
|
||||||
indent_size = false
|
indent_size = false
|
||||||
|
|
||||||
|
[test/fast/Listing versions/Running "nvm ls --no-alias" does not call into nvm_alias]
|
||||||
|
indent_size = false
|
||||||
|
|
||||||
[Makefile]
|
[Makefile]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
|
|
8
nvm.sh
8
nvm.sh
|
@ -3138,10 +3138,12 @@ nvm() {
|
||||||
"ls" | "list")
|
"ls" | "list")
|
||||||
local PATTERN
|
local PATTERN
|
||||||
local NVM_NO_COLORS
|
local NVM_NO_COLORS
|
||||||
|
local NVM_NO_ALIAS
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
--) ;;
|
--) ;;
|
||||||
--no-colors) NVM_NO_COLORS="${1}" ;;
|
--no-colors) NVM_NO_COLORS="${1}" ;;
|
||||||
|
--no-alias) NVM_NO_ALIAS="${1}" ;;
|
||||||
--*)
|
--*)
|
||||||
nvm_err "Unsupported option \"${1}\"."
|
nvm_err "Unsupported option \"${1}\"."
|
||||||
return 55
|
return 55
|
||||||
|
@ -3152,12 +3154,16 @@ nvm() {
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
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_OUTPUT
|
||||||
local NVM_LS_EXIT_CODE
|
local NVM_LS_EXIT_CODE
|
||||||
NVM_LS_OUTPUT=$(nvm_ls "${PATTERN-}")
|
NVM_LS_OUTPUT=$(nvm_ls "${PATTERN-}")
|
||||||
NVM_LS_EXIT_CODE=$?
|
NVM_LS_EXIT_CODE=$?
|
||||||
NVM_NO_COLORS="${NVM_NO_COLORS-}" nvm_print_versions "${NVM_LS_OUTPUT}"
|
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
|
if [ -n "${NVM_NO_COLORS-}" ]; then
|
||||||
nvm alias --no-colors
|
nvm alias --no-colors
|
||||||
else
|
else
|
||||||
|
|
|
@ -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}<"
|
|
@ -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}<"
|
Loading…
Reference in New Issue