Commit 22c73bf3 by Mislav Marohnić

Perform CLI argument validation as early as possible

parent 38ae3b56
...@@ -101,6 +101,8 @@ for option in "${OPTIONS[@]}"; do ...@@ -101,6 +101,8 @@ for option in "${OPTIONS[@]}"; do
esac esac
done done
[ "${#ARGUMENTS[@]}" -le 1 ] || usage 1
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
...@@ -111,9 +113,6 @@ DEFINITION="${ARGUMENTS[0]}" ...@@ -111,9 +113,6 @@ 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
# Fail if number of arguments is greater than 1
[ "${#ARGUMENTS[@]}" -le 1 ] || usage 1
# 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
# after the installation process. # after the installation process.
......
...@@ -33,6 +33,8 @@ if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then ...@@ -33,6 +33,8 @@ if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
shift shift
fi fi
[ "$#" -eq 1 ] || usage 1
DEFINITION="$1" DEFINITION="$1"
case "$DEFINITION" in case "$DEFINITION" in
"" | -* ) "" | -* )
...@@ -44,9 +46,6 @@ case "$DEFINITION" in ...@@ -44,9 +46,6 @@ case "$DEFINITION" in
;; ;;
esac esac
# Fail if number of arguments is not equal 1
[ "$#" -eq 1 ] || usage 1
declare -a before_hooks after_hooks declare -a before_hooks after_hooks
before_uninstall() { before_uninstall() {
......
...@@ -1022,6 +1022,8 @@ for option in "${OPTIONS[@]}"; do ...@@ -1022,6 +1022,8 @@ for option in "${OPTIONS[@]}"; do
esac esac
done done
[ "${#ARGUMENTS[@]}" -eq 2 ] || usage 1
DEFINITION_PATH="${ARGUMENTS[0]}" DEFINITION_PATH="${ARGUMENTS[0]}"
if [ -z "$DEFINITION_PATH" ]; then if [ -z "$DEFINITION_PATH" ]; then
usage usage
...@@ -1046,9 +1048,6 @@ elif [ "${PREFIX_PATH#/}" = "$PREFIX_PATH" ]; then ...@@ -1046,9 +1048,6 @@ elif [ "${PREFIX_PATH#/}" = "$PREFIX_PATH" ]; then
PREFIX_PATH="${PWD}/${PREFIX_PATH}" PREFIX_PATH="${PWD}/${PREFIX_PATH}"
fi fi
# Fail if number of arguments is not equal to 2
[ "${#ARGUMENTS[@]}" -eq 2 ] || usage
if [ -z "$TMPDIR" ]; then if [ -z "$TMPDIR" ]; then
TMP="/tmp" TMP="/tmp"
else 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