aboutsummaryrefslogtreecommitdiffstats
path: root/format.sh
blob: 5ba8e4df87fd4a0b8af609f3abb738c83ad52524 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh
set -e

if ! command -v odinfmt >/dev/null 2>&1; then
	echo "odinfmt not found. Build it from https://github.com/DanielGavin/ols (./odinfmt.sh) and put it on PATH."
	exit 1
fi

FILES=$(git ls-files --cached '*.odin')

if [ "$1" = "--check" ]; then
	BAD=0
	for f in $FILES; do
		if ! odinfmt "$f" | cmp -s - "$f"; then
			echo "not formatted: $f"
			BAD=1
		fi
	done
	if [ $BAD -ne 0 ]; then
		echo "run ./format.sh"
		exit 1
	fi
else
	for f in $FILES; do
		odinfmt -w "$f"
	done
fi