Skip to content

Commit 29f4a6e

Browse files
chore: fix cformat.sh (#15190)
## Description This fixes several issues in `cformat.sh` which only works for the use cases we have in the CI at the moment. The fix: - Makes the argument parsing actually work - Fixes the `$BASE_DIR` variable - Makes other tiny updates
1 parent 75241fe commit 29f4a6e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scripts/cformat.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ enumerate_files() {
4242
for ext in "${extensions[@]}"; do
4343
find_conditions+=("-o" "-name" "$ext")
4444
done
45-
unset 'find_conditions[-1]'
45+
find_conditions=("${find_conditions[@]:1}") # Remove first -o
4646
find "$BASE_DIR" -type f \( "${find_conditions[@]}" \)
4747
else
4848
git ls-files "${extensions[@]}"
@@ -52,7 +52,7 @@ enumerate_files() {
5252
# Script defaults
5353
UPDATE_MODE=false
5454
ENUM_ALL=false
55-
BASE_DIR=$(dirname "$(realpath "$0")")
55+
BASE_DIR=$(dirname "$(dirname "$(realpath "$0")")")
5656
CLANG_FORMAT=clang-format
5757

5858
# NB: consumes the arguments
@@ -67,20 +67,21 @@ while (( "$#" )); do
6767
*)
6868
;;
6969
esac
70+
shift
7071
done
7172

7273
# Environment variable overrides
7374
[[ -n "${CFORMAT_FIX:-}" ]] && UPDATE_MODE=true
7475
[[ -n "${CFORMAT_ALL:-}" ]] && ENUM_ALL=true
75-
[[ -n "${CFORMAT_BIN:-}" ]] && CLANG_FORMAT="$CLANG_FORMAT_BIN"
76+
[[ -n "${CFORMAT_BIN:-}" ]] && CLANG_FORMAT="$CFORMAT_BIN"
7677

7778
if [[ "$UPDATE_MODE" == "true" ]]; then
7879
# Update mode: Format files in-place
7980
enumerate_files \
8081
| exclude_patterns \
8182
| while IFS= read -r file; do
83+
echo "Formatting $file";
8284
${CLANG_FORMAT} -i "$file"
83-
echo "Formatting $file"
8485
done
8586
else
8687
# Check mode: Compare formatted output to existing files

0 commit comments

Comments
 (0)