Created
December 9, 2023 04:38
-
-
Save cwalv/467cee6bd086f80d32cc50947c0a2063 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
set -euo pipefail | |
declare -a PAT_ARGS | |
declare -a CAPTURE | |
declare PAT_COUNT=0 | |
while (("$#" > 0)) && [ "$1" != "--" ]; do | |
PAT_ARGS+=("--arg" "pat${PAT_COUNT}" "$1") | |
CAPTURE+=("capture(\$pat${PAT_COUNT})") | |
PAT_COUNT=$((PAT_COUNT + 1)) | |
shift | |
done | |
if (("$#" > 0)) && [ "$1" = "--" ]; then | |
shift | |
fi | |
CAPTURE_JSON="$(jq -r --raw-input \ | |
'split(" ") | |
| join(",") | |
| "[" + . + "]"' <<< "${CAPTURE[@]}")" | |
jq --stream --raw-input \ | |
"${PAT_ARGS[@]}" \ | |
"${CAPTURE_JSON} | add // empty" \ | |
"$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment