From 50e91f22a356d4bf9194ee9d9ad15c32ef869c31 Mon Sep 17 00:00:00 2001 From: Andy Brody Date: Mon, 28 Mar 2016 23:26:14 -0400 Subject: [PATCH 1/2] Skip alias versions, add --with-aliases option. 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] --- README.md | 1 + bin/rbenv-each | 78 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 55 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 6c8ea17..0a4066b 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,5 @@ the output. ``` $ rbenv each bundle install $ rbenv each -v rake test +$ rbenv each --with-aliases bundle check ``` diff --git a/bin/rbenv-each b/bin/rbenv-each index 7a1b725..151ddae 100755 --- a/bin/rbenv-each +++ b/bin/rbenv-each @@ -2,36 +2,60 @@ # # Summary: Execute a command for each Ruby version # -# Usage: rbenv each [-v] [arg1 arg2...] +# Usage: rbenv each [options] [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 +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 + ;; + -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="" @@ -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}" From 27ee84def92d355a0eb1dee31f32c0ddd6e4ca9c Mon Sep 17 00:00:00 2001 From: Andy Brody Date: Tue, 29 Mar 2016 20:37:52 -0400 Subject: [PATCH 2/2] Remove extra shift in --verbose processing. --- bin/rbenv-each | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/rbenv-each b/bin/rbenv-each index 151ddae..362d4ea 100755 --- a/bin/rbenv-each +++ b/bin/rbenv-each @@ -38,7 +38,6 @@ while [[ $1 == -* ]]; do ;; -v | --verbose ) verbose=1 - shift ;; -h | --help ) rbenv-help each