appimage: reduce some duplication in argument parsing

This commit is contained in:
Mike Salvatore 2021-05-03 09:28:40 -04:00
parent 684a6f8171
commit 998a14d248
1 changed files with 24 additions and 29 deletions

View File

@ -20,9 +20,11 @@ APP_TOOL_URL=https://github.com/AppImage/AppImageKit/releases/download/12/appima
PYTHON_VERSION="3.7.10" PYTHON_VERSION="3.7.10"
PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python${PYTHON_VERSION}-cp37-cp37m-manylinux1_x86_64.AppImage" PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python${PYTHON_VERSION}-cp37-cp37m-manylinux1_x86_64.AppImage"
missing_argument() { exit_if_missing_argument() {
echo "Error: Argument for $1 is missing" >&2 if [ -z "$2" ] || [ "${2:0:1}" == "-" ]; then
exit 1 echo "Error: Argument for $1 is missing" >&2
exit 1
fi
} }
echo_help() { echo_help() {
@ -292,52 +294,45 @@ apply_version_to_appimage() {
mv "Infection_Monkey-x86_64.AppImage" "Infection_Monkey-$1-x86_64.AppImage" mv "Infection_Monkey-x86_64.AppImage" "Infection_Monkey-$1-x86_64.AppImage"
} }
agent_binary_dir=""
as_root=false as_root=false
branch="develop"
monkey_repo="$DEFAULT_REPO_MONKEY_HOME" monkey_repo="$DEFAULT_REPO_MONKEY_HOME"
monkey_version="dev" monkey_version="dev"
agent_binary_dir=""
branch="develop"
while (( "$#" )); do while (( "$#" )); do
case "$1" in case "$1" in
--agent-binary-dir) --agent-binary-dir)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then exit_if_missing_argument "$1" "$2"
agent_binary_dir=$2
shift 2 agent_binary_dir=$2
else shift 2
missing_argument "$1"
fi
;; ;;
--as-root) --as-root)
as_root=true as_root=true
shift shift
;; ;;
--branch) --branch)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then exit_if_missing_argument "$1" "$2"
branch=$2
shift 2 branch=$2
else shift 2
missing_argument "$1"
fi
;; ;;
-h|--help) -h|--help)
echo_help echo_help
;; ;;
--monkey-repo) --monkey-repo)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then exit_if_missing_argument "$1" "$2"
monkey_repo=$2
shift 2 monkey_repo=$2
else shift 2
missing_argument "$1"
fi
;; ;;
--version) --version)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then exit_if_missing_argument "$1" "$2"
monkey_version=$2
shift 2 monkey_version=$2
else shift 2
missing_argument "$1"
fi
;; ;;
*) *)
echo "Error: Unsupported parameter $1" >&2 echo "Error: Unsupported parameter $1" >&2