#!/bin/bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
RUNS_DIR="$ROOT_DIR/.smbatcher/runs"
mkdir -p "$RUNS_DIR"

timestamp="$(date -Iseconds)"
log_file="$RUNS_DIR/run-$timestamp.log"

echo "time=${timestamp}" >>"$log_file"
echo "command=$*" >>"$log_file"
echo "status=pending" >>"$log_file"

"$@"
status=$?
echo "status=$status" >>"$log_file"
exit $status
