File: run_clang_format.sh

package info (click to toggle)
cpr 1.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,452 kB
  • sloc: cpp: 14,315; ansic: 637; sh: 139; xml: 38; makefile: 16
file content (30 lines) | stat: -rwxr-xr-x 781 bytes parent folder | download
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
#!/bin/bash

# Based on: https://gist.github.com/leilee/1d0915a583f8f29414cc21cd86e7151b
# Run from the project root directory as follows:
# ./scripts/run_clang_format.sh tests src

printf "📝  Running clang-format...\n"

function format() {
    for f in $(find $@ -name '*.h' -or -name '*.hpp' -or -name '*.c' -or -name '*.cpp'); do 
        echo "format ${f}";
        clang-format -i --style=file ${f};
    done

    echo "~~~ $@ directory formatted ~~~";
}

# Check all of the arguments first to make sure they're all directories
for dir in "$@"; do
    if [ ! -d "${dir}" ]; then
        echo "${dir} is not a directory";
    else
        format ${dir};
    fi
done

GREEN='\033[0;32m'
NC='\033[0m'

printf "✅ ${GREEN}Done. All files were formatted (if required).${NC}\n"