#!/usr/bin/env bash

set -e

python3 --version >/dev/null 2>&1 || (
    echo Error: failed to run Python with python3 --version.
    exit 1
)

script_dir="$(dirname "$0")"

# shellcheck disable=SC2046
export $(xargs <"${script_dir:?}/base-config")

CRUPEST_PROJECT_DIR="$(realpath "$script_dir/..")"
export CRUPEST_PROJECT_DIR

export PYTHONPATH="$CRUPEST_PROJECT_DIR/python:$PYTHONPATH"

if [[ "$#" != "0" ]] && [[ "$1" == "gen-tmpl" ]]; then
    python3 -m cru.service template generate "${@:2}"
else
    python3 -m cru.service "$@"
fi