journal/run.sh
2024-11-10 08:13:25 +00:00

38 lines
937 B
Bash
Executable file

#!/usr/bin/env bash
set -eu
WORKING_DIRECTORY=$(pwd)
TOOL_DIR="$(cd -- "$(dirname -- "$0")" && pwd)/tool"
cd "${WORKING_DIRECTORY}"
JQ=${JQ:-jq}
export JQ_FLAVOR=${JQ_FLAVOR:-"$(basename "${JQ}")"}
run() {
if [ -d "${TOOL_DIR}/lib/stubs/${JQ_FLAVOR}" ]; then
STUBS_DIR="${TOOL_DIR}/lib/stubs/${JQ_FLAVOR}"
else
STUBS_DIR="${TOOL_DIR}/lib/stubs/jq"
fi
FILES_ARGS=()
if [ "${EXPORT_FILE:-}" != "" ] && [ -f "${EXPORT_FILE}" ]; then
FILES_ARGS+=(--arg exportFileName "${EXPORT_FILE:-}")
if [ "${JQ_FLAVOR}" != "gojq-extended" ]; then
FILES_ARGS+=(--slurpfile exportFile "${EXPORT_FILE}")
fi
else
FILES_ARGS+=(--argjson exportFileName null)
FILES_ARGS+=(--argjson exportFile null)
fi
${JQ} -nr -L "$(realpath "${TOOL_DIR}")" -L "$(realpath "${TOOL_DIR}/lib")" -L "$(realpath "${STUBS_DIR}")" \
"${FILES_ARGS[@]}" \
'include "main"; main' \
--args -- "$@"
}
run "$@"