/
rbenv-each
executable file
·68 lines (57 loc) · 1.25 KB
/
rbenv-each
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
#
# Summary: Execute a command for each Ruby version
#
# Usage: rbenv each [-v] <command> [arg1 arg2...]
#
# Executes a command for each Ruby version by setting RBENV_VERSION.
# Failures are collected and reported at the end.
#
# -v Verbose mode. Prints a header for each ruby.
#
set -e
[ -n "$RBENV_DEBUG" ] && set -x
# Provide rbenv completions
if [ "$1" = "--complete" ]; then
echo -v
exit
fi
if [ "$1" = "-v" ]; then
verbose=1
shift
fi
case "$1" in
"" | -* )
rbenv-help --usage each >&2
exit 1
;;
esac
GRAY=""
RED=""
YELLOW=""
NORMAL=""
if [ -t 1 ]; then
GRAY="\033[1;30m"
RED="\033[0;31m"
YELLOW="\033[0;33m"
NORMAL="\033[0m"
fi
failed_rubies=""
trap "exit 1" INT
for ruby in $(rbenv versions --bare); do
if [ -n "$verbose" ]; then
header="===[$ruby]==================================================================="
header="${header:0:72}"
header="${header/[/[${YELLOW}}"
header="${header/]/${GRAY}]}"
echo -e "${GRAY}${header}${NORMAL}"
fi
STATUS=0
RBENV_VERSION="$ruby" "$@" || STATUS=$?
[ $STATUS -eq 0 ] || failed_rubies="$failed_rubies $ruby"
[ -n "$verbose" ] && echo
done
if [ -n "$failed_rubies" ]; then
echo -e "${RED}FAILED IN:${failed_rubies}${NORMAL}"
exit 1
fi