-
Notifications
You must be signed in to change notification settings - Fork 117
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
097c0a5
commit 7f7a251
Showing
2 changed files
with
30 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
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,9 +1,36 @@ | ||
#!/bin/bash | ||
|
||
# e.g. `format_files.sh <srcs_path>` | ||
# | ||
|
||
srcs_path=$1 | ||
set -euo pipefail | ||
|
||
exit_with_message() { | ||
local message=$1 | ||
local retcode="${2:-0}" | ||
|
||
echo 1>&2 "$message" | ||
exit "$retcode" | ||
} | ||
|
||
exit_with_clang_format_install_message() { | ||
exit_with_message "Skipping code formatting. Please install clang-format version 16 or greater: 'brew install clang-format'" | ||
} | ||
|
||
if ! [ -x "$(command -v clang-format)" ]; then | ||
exit_with_clang_format_install_message | ||
fi | ||
|
||
if ! [ "$(uname -s)" == "Darwin" ]; then | ||
exit 0 | ||
fi | ||
|
||
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
find "$srcs_path" -type f -name "*[.h|.m]" | xargs ./clang-format -i -style=file | ||
clang_format_version="$(clang-format --version | cut -f3 -w | tail)" | ||
clang_format_version_major=$(awk -F. '{print $1}' <<<"$clang_format_version") | ||
|
||
if [ "$clang_format_version_major" -lt 16 ]; then | ||
exit_with_clang_format_install_message | ||
fi | ||
|
||
srcs_path=$1 | ||
find "$srcs_path" -type f -name "*[.h|.m]" -exec clang-format -i -style=file "{}" \; |