2024-11-07 08:58:38 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
2024-11-10 08:13:25 +00:00
|
|
|
WORKING_DIRECTORY=$(pwd)
|
|
|
|
TOOL_DIR="$(cd -- "$(dirname -- "$0")" && pwd)/tool"
|
|
|
|
cd "${WORKING_DIRECTORY}"
|
2024-11-07 21:45:22 +00:00
|
|
|
|
|
|
|
JQ=${JQ:-jq}
|
2024-11-10 13:00:43 +00:00
|
|
|
export JQ_FLAVOUR=${JQ_FLAVOUR:-"$(basename "${JQ}")"}
|
2024-11-07 21:45:22 +00:00
|
|
|
|
|
|
|
run() {
|
2024-11-10 13:00:43 +00:00
|
|
|
if [ -d "${TOOL_DIR}/lib/stubs/${JQ_FLAVOUR}" ]; then
|
|
|
|
STUBS_DIR="${TOOL_DIR}/lib/stubs/${JQ_FLAVOUR}"
|
2024-11-10 08:13:25 +00:00
|
|
|
else
|
|
|
|
STUBS_DIR="${TOOL_DIR}/lib/stubs/jq"
|
|
|
|
fi
|
|
|
|
|
|
|
|
FILES_ARGS=()
|
|
|
|
if [ "${EXPORT_FILE:-}" != "" ] && [ -f "${EXPORT_FILE}" ]; then
|
|
|
|
FILES_ARGS+=(--arg exportFileName "${EXPORT_FILE:-}")
|
2024-11-10 13:00:43 +00:00
|
|
|
if [ "${JQ_FLAVOUR}" != "gojq-extended" ]; then
|
2024-11-10 08:13:25 +00:00
|
|
|
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[@]}" \
|
2024-11-07 21:45:22 +00:00
|
|
|
'include "main"; main' \
|
|
|
|
--args -- "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
run "$@"
|
2024-11-07 08:58:38 +00:00
|
|
|
|