39 lines
995 B
Bash
Executable File
39 lines
995 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# fix_format.sh — Auto-format all GDScript files with gdformat.
|
|
# Usage: ./tools/fix_format.sh
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
cd "$ROOT"
|
|
|
|
python_formatter() {
|
|
local python_command
|
|
for python_command in python python3; do
|
|
if command -v "$python_command" &>/dev/null &&
|
|
"$python_command" -m gdtoolkit.formatter --help &>/dev/null 2>&1; then
|
|
echo "$python_command"
|
|
return 0
|
|
fi
|
|
done
|
|
return 1
|
|
}
|
|
|
|
# detect gdformat
|
|
FMT=()
|
|
if [[ -x "$ROOT/.venv/bin/gdformat" ]]; then
|
|
FMT=("$ROOT/.venv/bin/gdformat")
|
|
elif command -v gdformat &>/dev/null; then
|
|
FMT=(gdformat)
|
|
elif PYTHON_FORMATTER="$(python_formatter)"; then
|
|
FMT=("$PYTHON_FORMATTER" -m gdtoolkit.formatter)
|
|
fi
|
|
|
|
if [[ ${#FMT[@]} -eq 0 ]]; then
|
|
echo "ERROR: gdformat not found. Install requirements-dev.txt; see docs/local_quality_gate.md."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Formatting all .gd files in $ROOT ..."
|
|
"${FMT[@]}" player simulation tests tools world
|
|
echo "Done."
|