Commit c1148857 by Kristofer White Committed by Mislav Marohnić

Add `rbenv install --skip-existing <VERSION>` option

The `-f` option allows for forcing installation of versions that already
exist in the environment. If that option isn't used, then an interactive
prompt is created which causes problems for non-interactive execution of
the command.

This change adds the `-s/--skip-existing` option to not install versions
that already exist, while still exiting as success.

Closes #543
parent 75b5cc3d
...@@ -6,15 +6,16 @@ ...@@ -6,15 +6,16 @@
# rbenv install [-f] [-kvp] <definition-file> # rbenv install [-f] [-kvp] <definition-file>
# rbenv install -l|--list # rbenv install -l|--list
# #
# -l/--list List all available versions # -l/--list List all available versions
# -f/--force Install even if the version appears to be installed already # -f/--force Install even if the version appears to be installed already
# -s/--skip-existing Skip if the version appears to be installed already
# #
# ruby-build options: # ruby-build options:
# #
# -k/--keep Keep source tree in $RBENV_BUILD_ROOT after installation # -k/--keep Keep source tree in $RBENV_BUILD_ROOT after installation
# (defaults to $RBENV_ROOT/sources) # (defaults to $RBENV_ROOT/sources)
# -v/--verbose Verbose mode: print compilation status to stdout # -v/--verbose Verbose mode: print compilation status to stdout
# -p/--patch Apply a patch from stdin before building # -p/--patch Apply a patch from stdin before building
# #
# For detailed information on installing Ruby versions with # For detailed information on installing Ruby versions with
# ruby-build, including a list of environment variables for adjusting # ruby-build, including a list of environment variables for adjusting
...@@ -51,6 +52,7 @@ indent() { ...@@ -51,6 +52,7 @@ indent() {
} }
unset FORCE unset FORCE
unset SKIP_EXISTING
unset KEEP unset KEEP
unset VERBOSE unset VERBOSE
unset HAS_PATCH unset HAS_PATCH
...@@ -69,6 +71,9 @@ for option in "${OPTIONS[@]}"; do ...@@ -69,6 +71,9 @@ for option in "${OPTIONS[@]}"; do
"f" | "force" ) "f" | "force" )
FORCE=true FORCE=true
;; ;;
"s" | "skip-existing" )
SKIP_EXISTING=true
;;
"k" | "keep" ) "k" | "keep" )
[ -n "${RBENV_BUILD_ROOT}" ] || RBENV_BUILD_ROOT="${RBENV_ROOT}/sources" [ -n "${RBENV_BUILD_ROOT}" ] || RBENV_BUILD_ROOT="${RBENV_ROOT}/sources"
;; ;;
...@@ -128,14 +133,21 @@ PREFIX="${RBENV_ROOT}/versions/${VERSION_NAME}" ...@@ -128,14 +133,21 @@ PREFIX="${RBENV_ROOT}/versions/${VERSION_NAME}"
# If the installation prefix exists, prompt for confirmation unless # If the installation prefix exists, prompt for confirmation unless
# the --force option was specified. # the --force option was specified.
if [ -z "$FORCE" ] && [ -d "${PREFIX}/bin" ]; then if [ -d "${PREFIX}/bin" ]; then
echo "rbenv: $PREFIX already exists" >&2 if [ -z "$FORCE" ] && [ -z "$SKIP_EXISTING" ]; then
read -p "continue with installation? (y/N) " echo "rbenv: $PREFIX already exists" >&2
read -p "continue with installation? (y/N) "
case "$REPLY" in
y* | Y* ) ;; case "$REPLY" in
* ) exit 1 ;; y* | Y* ) ;;
esac * ) exit 1 ;;
esac
elif [ -n "$SKIP_EXISTING" ]; then
# Since we know the ruby version is already installed, and are opting to
# not force installation of existing versions, we just `exit 0` here to
# leave things happy
exit 0
fi
fi fi
# If RBENV_BUILD_ROOT is set, always pass keep options to ruby-build. # If RBENV_BUILD_ROOT is set, always pass keep options to ruby-build.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment