Commit 4a6b9280 authored by Mislav Marohnić's avatar Mislav Marohnić
Browse files

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
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -96,12 +96,12 @@ for option in "${OPTIONS[@]}"; do
    exec ruby-build --version
    ;;
  * )
    usage 1
    usage 1 >&2
    ;;
  esac
done

[ "${#ARGUMENTS[@]}" -le 1 ] || usage 1
[ "${#ARGUMENTS[@]}" -le 1 ] || usage 1 >&2

unset VERSION_NAME

@@ -111,7 +111,7 @@ unset VERSION_NAME
# version is not specified.
DEFINITION="${ARGUMENTS[0]}"
[ -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
# plugin hooks to register a string of code for execution before or
+2 −6
Original line number Diff line number Diff line
@@ -33,16 +33,12 @@ if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
  shift
fi

[ "$#" -eq 1 ] || usage 1
[ "$#" -eq 1 ] || usage 1 >&2

DEFINITION="$1"
case "$DEFINITION" in
"" | -* )
  # We can remove the sed fallback once rbenv 0.4.0 is widely available.
  { rbenv-help uninstall 2>/dev/null ||
    sed -ne '/^#/!q;s/.\{1,2\}//;1,4d;p' < "$0"
  } >&2
  exit 1
  usage 1 >&2
  ;;
esac

+7 −9
Original line number Diff line number Diff line
@@ -957,11 +957,9 @@ usage() {
  { version
    echo "usage: ruby-build [-k|--keep] [-v|--verbose] [-p|--patch] definition prefix"
    echo "       ruby-build --definitions"
  } >&2
  } >&1

  if [ -z "$1" ]; then
    exit 1
  fi
  [ -z "$1" ] || exit "$1"
}

list_definitions() {
@@ -992,14 +990,14 @@ parse_options "$@"
for option in "${OPTIONS[@]}"; do
  case "$option" in
  "h" | "help" )
    usage without_exiting
    usage
    { echo
      echo "  -k/--keep        Do not remove source tree after installation"
      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
    } >&1
    exit 0
    ;;
  "definitions" )
@@ -1022,11 +1020,11 @@ for option in "${OPTIONS[@]}"; do
  esac
done

[ "${#ARGUMENTS[@]}" -eq 2 ] || usage 1
[ "${#ARGUMENTS[@]}" -eq 2 ] || usage 1 >&2

DEFINITION_PATH="${ARGUMENTS[0]}"
if [ -z "$DEFINITION_PATH" ]; then
  usage
  usage 1 >&2
elif [ ! -f "$DEFINITION_PATH" ]; then
  for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do
    if [ -f "${DEFINITION_DIR}/${DEFINITION_PATH}" ]; then
@@ -1043,7 +1041,7 @@ fi

PREFIX_PATH="${ARGUMENTS[1]}"
if [ -z "$PREFIX_PATH" ]; then
  usage
  usage 1 >&2
elif [ "${PREFIX_PATH#/}" = "$PREFIX_PATH" ]; then
  PREFIX_PATH="${PWD}/${PREFIX_PATH}"
fi