-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclangformat.sh
More file actions
executable file
·51 lines (45 loc) · 978 Bytes
/
clangformat.sh
File metadata and controls
executable file
·51 lines (45 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
set -euf -o pipefail
usage() {
echo "Usage: ${0} <src-dir> [-c/--check] [-h/--help]
-c/--check
Check the format but not perform actions
-h/--help
Show this page
"
}
POSITIONAL=()
CHECK_ONLY=false
#OPTIONS=(-style=file --verbose --sort-includes -i)
OPTIONS=(-style=file --verbose -i)
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-c | --check)
CHECK_ONLY=true
;;
-h | --help)
usage
exit 0
;;
*)
POSITIONAL+=("$1")
;;
esac
shift
done
if [[ ${#POSITIONAL[*]} -gt 0 ]]; then
set -- "${POSITIONAL[*]}"
FORMAT_DIR=$1
else
usage
exit 1
fi
if [[ ${CHECK_ONLY} == true ]]; then
OPTIONS+=(-n -Werror)
echo "Checking dir: ${1}"
else
echo "Formating dir: ${1}"
fi
echo "pwd $(pwd)"
find "${FORMAT_DIR}" -type f \( -name '*.h' -or -name '*.hpp' -or -name '*.cpp' -or -name '*.c' -or -name '*.cc' \) -print | grep -v cmake-build-debug | grep -v CMakeFiles | xargs clang-format -style="file" -i ${OPTIONS[*]}