Skip to content

Commit a2c7556

Browse files
committed
chore(runformat): Improve script to check version only if found
1 parent a8ac476 commit a2c7556

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

runformat

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@ cd "$SCRIPT_DIR"
1717
UNCRUSTIFY_VERSION="0.72.0"
1818
UNCRUSTIFY="${UNCRUSTIFY-uncrustify}"
1919

20-
DETECTED_VERSION=$("$UNCRUSTIFY" --version 2>&1 | grep -o -E '[0-9.]+')
21-
if [ "$DETECTED_VERSION" != "${UNCRUSTIFY_VERSION}" ]; then
22-
echo "You should use version: ${UNCRUSTIFY_VERSION}"
23-
echo "Detected version: ${DETECTED_VERSION}"
24-
exit 1
20+
err() { echo -e >&2 "ERROR: $@\n"; }
21+
die() { err $@; exit 1; }
22+
23+
# Check Uncrustify availability
24+
if ! command -v "$UNCRUSTIFY" >/dev/null 2>&1; then
25+
err "Uncrustify executable not found: $UNCRUSTIFY"
26+
die "Add it to PATH or set UNCRUSTIFY=/path/to/uncrustify"
27+
fi
28+
29+
# Version check
30+
DETECTED_VERSION="$("$UNCRUSTIFY" --version 2>&1 | grep -oE '[0-9]+(\.[0-9]+)*' | head -n1 || true)"
31+
echo "Detected Uncrustify: ${DETECTED_VERSION:-unknown}"
32+
if [[ "$DETECTED_VERSION" != "${UNCRUSTIFY_VERSION}" ]]; then
33+
die "Expected Uncrustify ${UNCRUSTIFY_VERSION}."
2534
fi
2635

2736
$UNCRUSTIFY -c .uncrustify.cfg --no-backup *.cpp *.h

0 commit comments

Comments
 (0)