Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ the output.
```
$ rbenv each bundle install
$ rbenv each -v rake test
$ rbenv each --with-aliases bundle check
```
78 changes: 54 additions & 24 deletions bin/rbenv-each
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,60 @@
#
# Summary: Execute a command for each Ruby version
#
# Usage: rbenv each [-v] <command> [arg1 arg2...]
# Usage: rbenv each [options] <command> [arg1 arg2...]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted this to say [-va] instead of options but I realized that our option parsing doesn't support combining multiple shorthand flags together. So these docs will do for now.

#
# Executes a command for each Ruby version by setting RBENV_VERSION.
# Execute 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.
#
# Options:
# -h, --help Print this help message
# -a, --with-aliases Don't skip ruby versions that are aliases (symlinks)
# -v, --verbose Verbose mode: print a header for each ruby version
#
set -e
[ -n "$RBENV_DEBUG" ] && set -x

# Provide rbenv completions
case "$1" in
--complete )
echo --help
echo --verbose
exit
;;
-v | --verbose )
verbose=1
shift
;;
--help )
rbenv-help each
exit
;;
"" | -* )
rbenv-help --usage each >&2
exit 1
;;
esac
aliases=
verbose=

while [[ $1 == -* ]]; do
case "$1" in
--)
shift
break
;;

# Provide rbenv completions
--complete )
echo --help
echo --verbose
echo --with-aliases
exit
;;
-a | --with-aliases )
aliases=1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this block needs a shift?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's after the esac. The -- block needed one specially because the break skips it.

EDIT: Oh I see, --verbose has an extra one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's what got me confused.

;;
-v | --verbose )
verbose=1
shift
;;
-h | --help )
rbenv-help each
exit
;;
"" | -* )
rbenv-help --usage each >&2
exit 1
;;
esac
shift
done

if [ $# -lt 1 ]; then
rbenv-help --usage each >&2
exit 1
fi

GRAY=""
RED=""
Expand All @@ -49,7 +73,13 @@ failed_rubies=""

trap "exit 1" INT

for ruby in $(rbenv versions --bare); do
if [ -n "$aliases" ]; then
opts=
else
opts="--skip-aliases"
fi

for ruby in $(rbenv versions --bare $opts); do
if [ -n "$verbose" ]; then
header="===[$ruby]==================================================================="
header="${header:0:72}"
Expand Down