Files
ChatGPTScaffolding/scripts/toolwrap.sh

41 lines
858 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Quiet command wrapper:
# - Runs the given command without emitting stdout/stderr to the console.
# - On success: prints nothing; logs an optional one-line summary to tool.log.
# - On failure: writes full stdout/stderr to tool.log and exits non-zero.
log_file="docs/devlog/tool.log"
mkdir -p "$(dirname "$log_file")"
ts() { date -u +"%Y-%m-%dT%H:%M:%SZ"; }
cmd=("$@")
# Capture stdout/stderr
out_file="$(mktemp)"
err_file="$(mktemp)"
rc=0
{"${cmd[@]}"} >"$out_file" 2>"$err_file" || rc=$?
if [ "$rc" -eq 0 ]; then
echo "$(ts) SUCCESS: ${cmd[*]}" >> "$log_file"
rm -f "$out_file" "$err_file"
exit 0
fi
{
echo "$(ts) FAILURE: ${cmd[*]}"
echo "--- STDOUT ---"
cat "$out_file"
echo "--- STDERR ---"
cat "$err_file"
echo "--------------"
} >> "$log_file"
rm -f "$out_file" "$err_file"
exit "$rc"