-
Notifications
You must be signed in to change notification settings - Fork 59
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
loikki
committed
Aug 23, 2018
1 parent
91bb16c
commit 8ec2da6
Showing
4 changed files
with
75 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,69 @@ | ||
#!/bin/bash | ||
|
||
clang-format-5.0 -style=file -i src/*.[ch] src/*/*.[ch] src/*/*/*.[ch] examples/main.c tests/*.[ch] | ||
# Clang software name | ||
clang="clang-format-5.0" | ||
|
||
# Formatting command | ||
cmd="$clang -style=file src/*.[ch] src/*/*.[ch] src/*/*/*.[ch] examples/main.c tests/*.[ch]" | ||
|
||
# Test if `clang-format-5.0` works | ||
command -v $clang > /dev/null | ||
if [[ $? -ne 0 ]] | ||
then | ||
echo "Cannot find $clang" | ||
exit 1 | ||
fi | ||
|
||
set -e | ||
|
||
|
||
# Print the help | ||
function show_help { | ||
echo -e "This script formats Swift according to Google style" | ||
echo -e " -h, --help \t Show this help" | ||
echo -e " -t, --test \t Test if Swift is well formatted" | ||
} | ||
|
||
# Parse arguments (based on https://stackoverflow.com/questions/192249) | ||
TEST=0 | ||
while [[ $# -gt 0 ]] | ||
do | ||
key="$1" | ||
|
||
case $key in | ||
# print the help and exit | ||
-h|--help) | ||
show_help | ||
exit | ||
;; | ||
# check if the code is well formatted | ||
-t|--test) | ||
TEST=1 | ||
shift | ||
;; | ||
# unknown option | ||
*) | ||
echo "Argument '$1' not implemented" | ||
show_help | ||
exit | ||
;; | ||
esac | ||
done | ||
|
||
# Run the required commands | ||
if [[ $TEST -eq 1 ]] | ||
then | ||
echo "Testing Swift formatting" | ||
$cmd -output-replacements-xml | grep -c "<replacement " >/dev/null | ||
res=$? | ||
|
||
# Check formatting | ||
if [[ $res -ne 1 ]] | ||
then | ||
echo "Swift needs to be formatted" | ||
exit 1 | ||
fi | ||
else | ||
echo "Formatting Swift" | ||
$cmd -i | ||
fi |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
cd @srcdir@/.. | ||
./format.sh --test |