Skip to content

Commit 1239e91

Browse files
committed
ci: enhance format-files script with error handling and check mode
1 parent 0b80726 commit 1239e91

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

format-files.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/env bash
22

3+
set -euo pipefail
4+
5+
MODE="${1:-default}"
6+
37
PROJ_ROOT=$(dirname $0)
48

59
if ! type -p clang-format >/dev/null; then
@@ -21,7 +25,13 @@ else
2125
exit 1
2226
fi
2327

28+
EXTRA_FLAGS=""
29+
if [[ "$MODE" == "check" ]]; then
30+
echo "check mode enabled, not formatting files, only checking"
31+
EXTRA_FLAGS="--dry-run --Werror"
32+
fi
33+
2434
find "${PROJ_ROOT}" -type f \
2535
\( -name "*.cpp" -o -name "*.c" -o -name "*.hpp" -o -name "*.h" \) \
2636
-not -path "${PROJ_ROOT}/build/*" \
27-
-print -exec clang-format --style=file -i '{}' \;
37+
-print0 | xargs -0 clang-format $EXTRA_FLAGS --style=file --verbose -i

0 commit comments

Comments
 (0)