Commit c1148857 authored by Kristofer White's avatar Kristofer White Committed by Mislav Marohnić
Browse files

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
Loading
Loading
Loading
Loading
+26 −14
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
#
#   -l/--list          List all available versions
#   -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:
#
@@ -51,6 +52,7 @@ indent() {
}

unset FORCE
unset SKIP_EXISTING
unset KEEP
unset VERBOSE
unset HAS_PATCH
@@ -69,6 +71,9 @@ for option in "${OPTIONS[@]}"; do
  "f" | "force" )
    FORCE=true
    ;;
  "s" | "skip-existing" )
    SKIP_EXISTING=true
    ;;
  "k" | "keep" )
    [ -n "${RBENV_BUILD_ROOT}" ] || RBENV_BUILD_ROOT="${RBENV_ROOT}/sources"
    ;;
@@ -128,7 +133,8 @@ PREFIX="${RBENV_ROOT}/versions/${VERSION_NAME}"

# If the installation prefix exists, prompt for confirmation unless
# the --force option was specified.
if [ -z "$FORCE" ] && [ -d "${PREFIX}/bin" ]; then
if [ -d "${PREFIX}/bin" ]; then
  if [ -z "$FORCE" ] && [ -z "$SKIP_EXISTING" ]; then
    echo "rbenv: $PREFIX already exists" >&2
    read -p "continue with installation? (y/N) "

@@ -136,6 +142,12 @@ if [ -z "$FORCE" ] && [ -d "${PREFIX}/bin" ]; then
    y* | Y* ) ;;
    * ) 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

# If RBENV_BUILD_ROOT is set, always pass keep options to ruby-build.