#!/usr/bin/env bash set -eu WORKING_DIRECTORY=$(pwd) TOOL_DIR="$(cd -- "$(dirname -- "$0")" && pwd)/tool" cd "${WORKING_DIRECTORY}" JQ=${JQ:-jq} export JQ_FLAVOUR=${JQ_FLAVOUR:-"$(basename "${JQ}")"} run() { if [ -d "${TOOL_DIR}/lib/stubs/${JQ_FLAVOUR}" ]; then STUBS_DIR="${TOOL_DIR}/lib/stubs/${JQ_FLAVOUR}" 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_FLAVOUR}" != "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 "$@"