File: format.sh

package info (click to toggle)
dd-opentracing-cpp 1.3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,336 kB
  • sloc: cpp: 44,895; sh: 697; ansic: 27; makefile: 20
file content (44 lines) | stat: -rwxr-xr-x 814 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh

# Exit if a non-conditional command returns a nonzero exit status.
set -e

usage() {
    argv0="$0"

    cat <<END_USAGE
format.sh - format Datadog C++ source code

usage:

    $argv0 FILES ...
        Format the specified files in place.

    $argv0
        Format all Datadog-owned C++ code in this repository.

    $argv0 -h
    $argv0 --help
        Print this message.
END_USAGE
}

is_help_flag() {
    [ "$1" = '-h' ] || [ "$1" = '--help' ]
}

if [ $# -eq 1 ] && is_help_flag "$1"; then
    usage
    exit
fi

formatter=clang-format-9

if [ $# -eq 0 ]; then
    cd "$(git rev-parse --show-toplevel)"
    find src/ include/ test/ examples/ \
        -type f \( -name '*.h' -o -name '*.cpp' \) -print0 \
    | xargs -0 "$formatter" -i --style=file
else
    exec "$formatter" -i --style=file "$@"
fi