Created
August 19, 2022 19:18
-
-
Save bskinner/e6ad9d9a17ef49f2ca17e8695a3a5a32 to your computer and use it in GitHub Desktop.
studybuilder-cli "Run Task..." helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
STUDY="${STUDY:-""}" | |
TASK="${TASK:-""}" | |
set-value() { | |
local param_name=$1 | |
local param_value=$2 | |
local env_target=$3 | |
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then | |
export "$3"=$2 | |
return 0 | |
else | |
echo "Error: Value for $1 is missing." | |
return 1 | |
fi | |
} | |
required() { | |
if [ $# -lt 2 ]; then | |
echo "$1" | |
return 1 | |
fi | |
return 0 | |
} | |
main() { | |
pushd ../ 1>/dev/null | |
mvn \ | |
-DskipTests \ | |
-pl studybuilder-cli \ | |
-am \ | |
clean install | |
popd 1>/dev/null | |
java \ | |
-Dconfig.file="${PWD}/output-config/application.conf" \ | |
-jar "./target/StudyBuilder.jar" \ | |
--vars "./output-config/vars.conf" \ | |
--substitutions "./studies/$STUDY/substitutions.conf" \ | |
"./studies/$STUDY/study.conf" \ | |
--run-task "$TASK" | |
} | |
POSITIONAL="" | |
while (( "$#" )); do | |
case "$1" in | |
-s|--study) | |
if ! set-value $1 $2 STUDY; then | |
exit 1 | |
fi | |
shift 2 | |
;; | |
-t|--task) | |
if ! set-value $1 $2 TASK; then | |
exit 1 | |
fi | |
shift 2 | |
;; | |
-*|--*) | |
echo "Error: Unsupported flag $1" | |
exit 1 | |
;; | |
*) | |
POSITIONAL="${POSITIONAL} $1" | |
shift | |
;; | |
esac | |
done | |
eval set -- "$POSITIONAL" | |
required $STUDY "Error: a study guid must be specified" | |
required $TASK "Error: a task name must be specified" | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment