-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9674639
commit 49a9550
Showing
4 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,35 @@ | ||
#!/bin/bash | ||
|
||
# Recursively find .hpp files and format them with clang-format | ||
find . -type f -name "*.hpp" -o -name "*.cpp" -exec clang-format -i {} \; | ||
format_check=false | ||
if [[ "$1" == "--check" ]]; then | ||
format_check=true | ||
fi | ||
|
||
run_clang_format() { | ||
local file="$1" | ||
if [[ "$format_check" == true ]]; then | ||
clang-format-17 --dry-run --Werror "$file" | ||
else | ||
clang-format-17 -i "$file" | ||
fi | ||
} | ||
|
||
# Count the number of files to format | ||
file_count=$(find . -type f \( -name "*.hpp" -o -name "*.cpp" \) | wc -l) | ||
if [[ "$format_check" == true ]]; then | ||
echo "Files to check: $file_count" | ||
else | ||
echo "Files to format: $file_count" | ||
fi | ||
echo | ||
|
||
# Iterate over the files and run format/check | ||
file_number=0 | ||
find . -type f \( -name "*.hpp" -o -name "*.cpp" \) -print0 | while IFS= read -r -d '' file; do | ||
((file_number++)) | ||
echo "[$file_number/$file_count] $file" | ||
run_clang_format "$file" | ||
done | ||
|
||
echo | ||
echo "Done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,37 @@ | ||
# Recursively find .hpp files and format them with clang-format | ||
Get-ChildItem -Recurse -Include *.hpp, *.cpp | ForEach-Object { clang-format -i $_.FullName } | ||
$formatCheck = $false | ||
if ($args[0] -eq "--check") { | ||
$formatCheck = $true | ||
} | ||
|
||
function Run-Clang-Format { | ||
param ( | ||
[string]$filePath, | ||
[bool]$check | ||
) | ||
|
||
if ($check) { | ||
clang-format --dry-run --Werror $filePath | ||
} | ||
else { | ||
clang-format -i $filePath | ||
} | ||
} | ||
|
||
# Get the list of files to format | ||
$files = Get-ChildItem -Recurse -Include *.hpp, *.cpp | ||
|
||
# Count the number of files to format | ||
$fileCount = $files.Count | ||
Write-Host "Total files to format: $fileCount" | ||
Write-Host | ||
|
||
# Iterate over the files and run format/check | ||
$fileNumber = 0 | ||
foreach ($file in $files) { | ||
$fileNumber++ | ||
Write-Host "[$fileNumber/$fileCount] $($file.FullName)" | ||
Run-Clang-Format -filePath $file.FullName -check $formatCheck | ||
} | ||
|
||
Write-Host | ||
Write-Host "Done!" |