Commit 4a6b9280 by Mislav Marohnić

Provide CLI usage help on stout/stderr appropriately

When requested via `-h|--help`, usage text should be displayed on stdout
and the exit status should be 0.

When usage text is shown due to invalid arguments, it should be
printed to stderr and exit status should be 1.
parent 22c73bf3
...@@ -96,12 +96,12 @@ for option in "${OPTIONS[@]}"; do ...@@ -96,12 +96,12 @@ 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 [ "${#ARGUMENTS[@]}" -le 1 ] || usage 1 >&2
unset VERSION_NAME unset VERSION_NAME
...@@ -111,7 +111,7 @@ unset VERSION_NAME ...@@ -111,7 +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
......
...@@ -33,16 +33,12 @@ if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then ...@@ -33,16 +33,12 @@ if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
shift shift
fi fi
[ "$#" -eq 1 ] || usage 1 [ "$#" -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
......
...@@ -957,11 +957,9 @@ usage() { ...@@ -957,11 +957,9 @@ usage() {
{ version { version
echo "usage: ruby-build [-k|--keep] [-v|--verbose] [-p|--patch] definition prefix" echo "usage: ruby-build [-k|--keep] [-v|--verbose] [-p|--patch] definition prefix"
echo " ruby-build --definitions" echo " ruby-build --definitions"
} >&2 } >&1
if [ -z "$1" ]; then [ -z "$1" ] || exit "$1"
exit 1
fi
} }
list_definitions() { list_definitions() {
...@@ -992,14 +990,14 @@ parse_options "$@" ...@@ -992,14 +990,14 @@ 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 usage
{ echo { echo
echo " -k/--keep Do not remove source tree after installation" echo " -k/--keep Do not remove source tree after installation"
echo " -v/--verbose Verbose mode: print compilation status to stdout" echo " -v/--verbose Verbose mode: print compilation status to stdout"
echo " -p/--patch Apply a patch from stdin before building" echo " -p/--patch Apply a patch from stdin before building"
echo " --definitions List all built-in definitions" echo " --definitions List all built-in definitions"
echo echo
} >&2 } >&1
exit 0 exit 0
;; ;;
"definitions" ) "definitions" )
...@@ -1022,11 +1020,11 @@ for option in "${OPTIONS[@]}"; do ...@@ -1022,11 +1020,11 @@ for option in "${OPTIONS[@]}"; do
esac esac
done done
[ "${#ARGUMENTS[@]}" -eq 2 ] || usage 1 [ "${#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
...@@ -1043,7 +1041,7 @@ fi ...@@ -1043,7 +1041,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
......
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