Commit 22c73bf3 authored by Mislav Marohnić's avatar Mislav Marohnić
Browse files

Perform CLI argument validation as early as possible

parent 38ae3b56
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -101,6 +101,8 @@ for option in "${OPTIONS[@]}"; do
  esac
done

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

unset VERSION_NAME

# The first argument contains the definition to install. If the
@@ -111,9 +113,6 @@ DEFINITION="${ARGUMENTS[0]}"
[ -n "$DEFINITION" ] || DEFINITION="$(rbenv-local 2>/dev/null || true)"
[ -n "$DEFINITION" ] || usage 1

# Fail if number of arguments is greater than 1
[ "${#ARGUMENTS[@]}" -le 1 ] || usage 1

# Define `before_install` and `after_install` functions that allow
# plugin hooks to register a string of code for execution before or
# after the installation process.
+2 −3
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
  shift
fi

[ "$#" -eq 1 ] || usage 1

DEFINITION="$1"
case "$DEFINITION" in
"" | -* )
@@ -44,9 +46,6 @@ case "$DEFINITION" in
  ;;
esac

# Fail if number of arguments is not equal 1
[ "$#" -eq 1 ] || usage 1

declare -a before_hooks after_hooks

before_uninstall() {
+2 −3
Original line number Diff line number Diff line
@@ -1022,6 +1022,8 @@ for option in "${OPTIONS[@]}"; do
  esac
done

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

DEFINITION_PATH="${ARGUMENTS[0]}"
if [ -z "$DEFINITION_PATH" ]; then
  usage
@@ -1046,9 +1048,6 @@ elif [ "${PREFIX_PATH#/}" = "$PREFIX_PATH" ]; then
  PREFIX_PATH="${PWD}/${PREFIX_PATH}"
fi

# Fail if number of arguments is not equal to 2
[ "${#ARGUMENTS[@]}" -eq 2 ] || usage

if [ -z "$TMPDIR" ]; then
  TMP="/tmp"
else