#!/usr/bin/env bash
set -euo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")/.."
CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
"$CLANG_FORMAT" --version

find src cli test/src python/src jni/src apple/src apple/include wasm/src \
  -type f \( -iname '*.hpp' -o -iname '*.cpp' -o -iname '*.cc' \
             -o -iname '*.h' -o -iname '*.mm' \) -print0 |
  while IFS= read -r -d '' file; do
    echo "Formatting $file"
    "$CLANG_FORMAT" --style=file -i "$file"
  done
