Commit aa1976b2 by Mislav Marohnić

Merge branch 'extra-arguments'

Fixes #667, closes #668
parents 63f6fa2e 34246f9f
...@@ -96,11 +96,13 @@ for option in "${OPTIONS[@]}"; do ...@@ -96,11 +96,13 @@ for option in "${OPTIONS[@]}"; do
exec ruby-build --version exec ruby-build --version
;; ;;
* ) * )
usage 1 usage 1 >&2
;; ;;
esac esac
done done
[ "${#ARGUMENTS[@]}" -le 1 ] || usage 1 >&2
unset VERSION_NAME unset VERSION_NAME
# The first argument contains the definition to install. If the # The first argument contains the definition to install. If the
...@@ -109,8 +111,7 @@ unset VERSION_NAME ...@@ -109,8 +111,7 @@ unset VERSION_NAME
# version is not specified. # version is not specified.
DEFINITION="${ARGUMENTS[0]}" DEFINITION="${ARGUMENTS[0]}"
[ -n "$DEFINITION" ] || DEFINITION="$(rbenv-local 2>/dev/null || true)" [ -n "$DEFINITION" ] || DEFINITION="$(rbenv-local 2>/dev/null || true)"
[ -n "$DEFINITION" ] || usage 1 [ -n "$DEFINITION" ] || usage 1 >&2
# Define `before_install` and `after_install` functions that allow # Define `before_install` and `after_install` functions that allow
# plugin hooks to register a string of code for execution before or # plugin hooks to register a string of code for execution before or
......
...@@ -17,24 +17,32 @@ if [ "$1" = "--complete" ]; then ...@@ -17,24 +17,32 @@ if [ "$1" = "--complete" ]; then
exec rbenv versions --bare exec rbenv versions --bare
fi fi
usage() {
# We can remove the sed fallback once rbenv 0.4.0 is widely available.
rbenv-help uninstall 2>/dev/null || sed -ne '/^#/!q;s/.//;s/.//;1,4d;p' < "$0"
[ -z "$1" ] || exit "$1"
}
if [ -z "$RBENV_ROOT" ]; then if [ -z "$RBENV_ROOT" ]; then
RBENV_ROOT="${HOME}/.rbenv" RBENV_ROOT="${HOME}/.rbenv"
fi fi
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage 0
fi
unset FORCE unset FORCE
if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
FORCE=true FORCE=true
shift shift
fi fi
[ "$#" -eq 1 ] || usage 1 >&2
DEFINITION="$1" DEFINITION="$1"
case "$DEFINITION" in case "$DEFINITION" in
"" | -* ) "" | -* )
# We can remove the sed fallback once rbenv 0.4.0 is widely available. usage 1 >&2
{ rbenv-help uninstall 2>/dev/null ||
sed -ne '/^#/!q;s/.\{1,2\}//;1,4d;p' < "$0"
} >&2
exit 1
;; ;;
esac esac
......
#!/usr/bin/env bash #!/usr/bin/env bash
#
# Usage: ruby-build [-kvp] <definition> <prefix>
# ruby-build --definitions
#
# -k/--keep Do not remove source tree after installation
# -v/--verbose Verbose mode: print compilation status to stdout
# -p/--patch Apply a patch from stdin before building
# --definitions List all built-in definitions
#
RUBY_BUILD_VERSION="20141113" RUBY_BUILD_VERSION="20141113"
...@@ -954,14 +963,8 @@ version() { ...@@ -954,14 +963,8 @@ version() {
} }
usage() { usage() {
{ version sed -ne '/^#/!q;s/.\{1,2\}//;1,2d;p' < "$0"
echo "usage: ruby-build [-k|--keep] [-v|--verbose] [-p|--patch] definition prefix" [ -z "$1" ] || exit "$1"
echo " ruby-build --definitions"
} >&2
if [ -z "$1" ]; then
exit 1
fi
} }
list_definitions() { list_definitions() {
...@@ -992,15 +995,9 @@ parse_options "$@" ...@@ -992,15 +995,9 @@ parse_options "$@"
for option in "${OPTIONS[@]}"; do for option in "${OPTIONS[@]}"; do
case "$option" in case "$option" in
"h" | "help" ) "h" | "help" )
usage without_exiting version
{ echo echo
echo " -k/--keep Do not remove source tree after installation" usage 0
echo " -v/--verbose Verbose mode: print compilation status to stdout"
echo " -p/--patch Apply a patch from stdin before building"
echo " --definitions List all built-in definitions"
echo
} >&2
exit 0
;; ;;
"definitions" ) "definitions" )
list_definitions list_definitions
...@@ -1022,9 +1019,11 @@ for option in "${OPTIONS[@]}"; do ...@@ -1022,9 +1019,11 @@ for option in "${OPTIONS[@]}"; do
esac esac
done done
[ "${#ARGUMENTS[@]}" -eq 2 ] || usage 1 >&2
DEFINITION_PATH="${ARGUMENTS[0]}" DEFINITION_PATH="${ARGUMENTS[0]}"
if [ -z "$DEFINITION_PATH" ]; then if [ -z "$DEFINITION_PATH" ]; then
usage usage 1 >&2
elif [ ! -f "$DEFINITION_PATH" ]; then elif [ ! -f "$DEFINITION_PATH" ]; then
for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do
if [ -f "${DEFINITION_DIR}/${DEFINITION_PATH}" ]; then if [ -f "${DEFINITION_DIR}/${DEFINITION_PATH}" ]; then
...@@ -1041,7 +1040,7 @@ fi ...@@ -1041,7 +1040,7 @@ fi
PREFIX_PATH="${ARGUMENTS[1]}" PREFIX_PATH="${ARGUMENTS[1]}"
if [ -z "$PREFIX_PATH" ]; then if [ -z "$PREFIX_PATH" ]; then
usage usage 1 >&2
elif [ "${PREFIX_PATH#/}" = "$PREFIX_PATH" ]; then elif [ "${PREFIX_PATH#/}" = "$PREFIX_PATH" ]; then
PREFIX_PATH="${PWD}/${PREFIX_PATH}" PREFIX_PATH="${PWD}/${PREFIX_PATH}"
fi fi
......
#!/usr/bin/env bats
load test_helper
@test "not enought arguments for ruby-build" {
# use empty inline definition so nothing gets built anyway
local definition="${TMP}/build-definition"
echo '' > "$definition"
run ruby-build "$definition"
assert_failure
assert_output_contains 'Usage: ruby-build'
}
@test "extra arguments for ruby-build" {
# use empty inline definition so nothing gets built anyway
local definition="${TMP}/build-definition"
echo '' > "$definition"
run ruby-build "$definition" "${TMP}/install" ""
assert_failure
assert_output_contains 'Usage: ruby-build'
}
...@@ -146,3 +146,42 @@ ${RBENV_ROOT}/plugins/bar/share/ruby-build ...@@ -146,3 +146,42 @@ ${RBENV_ROOT}/plugins/bar/share/ruby-build
${RBENV_ROOT}/plugins/foo/share/ruby-build ${RBENV_ROOT}/plugins/foo/share/ruby-build
OUT OUT
} }
@test "not enough arguments for rbenv-install" {
stub_ruby_build
run rbenv-install
assert_failure
assert_output_contains 'Usage: rbenv install'
}
@test "too many arguments for rbenv-install" {
stub_ruby_build
run rbenv-install 2.1.1 2.1.2
assert_failure
assert_output_contains 'Usage: rbenv install'
}
@test "show help for rbenv-install" {
stub_ruby_build
run rbenv-install -h
assert_success
assert_output_contains 'Usage: rbenv install'
}
@test "not enough arguments rbenv-uninstall" {
run rbenv-uninstall
assert_failure
assert_output_contains 'Usage: rbenv uninstall'
}
@test "too many arguments for rbenv-uninstall" {
run rbenv-uninstall 2.1.1 2.1.2
assert_failure
assert_output_contains 'Usage: rbenv uninstall'
}
@test "show help for rbenv-uninstall" {
run rbenv-uninstall -h
assert_success
assert_output_contains 'Usage: rbenv uninstall'
}
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