Commit 22c73bf3 by Mislav Marohnić

Perform CLI argument validation as early as possible

parent 38ae3b56
......@@ -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.
......
......@@ -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() {
......
......@@ -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
......
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