Skip to content

Commit

Permalink
Skip alias versions, add --with-aliases option.
Browse files Browse the repository at this point in the history
By default, skip ruby versions that are aliases. I'm having a hard time
thinking of any reason you would want to run the command on the same
ruby version multiple times by default.

Also tweak the option parsing and usage messages in support of this
change.

With versions `2.1 => 2.1.7`, `2.1.6`, and `2.1.7`:

    $ rbenv each ruby --version
    ruby 2.1.6p336 (2015-04-13 revision 50298) [x86_64-linux]
    ruby 2.1.7p400 (2015-08-18 revision 51632) [x86_64-linux]

    $ rbenv each --with-aliases ruby --version
    ruby 2.1.7p400 (2015-08-18 revision 51632) [x86_64-linux]
    ruby 2.1.6p336 (2015-04-13 revision 50298) [x86_64-linux]
    ruby 2.1.7p400 (2015-08-18 revision 51632) [x86_64-linux]
  • Loading branch information
ab committed Mar 29, 2016
1 parent ba46d74 commit 50fc068
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 24 deletions.
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
```
75 changes: 51 additions & 24 deletions bin/rbenv-each
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,57 @@
#
# Summary: Execute a command for each Ruby version
#
# Usage: rbenv each [-v] <command> [arg1 arg2...]
# Usage: rbenv each [options] <command> [arg1 arg2...]
#
# 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
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
;;
-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 +70,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

0 comments on commit 50fc068

Please sign in to comment.