-
Notifications
You must be signed in to change notification settings - Fork 105
/
format
executable file
·60 lines (42 loc) · 1.03 KB
/
format
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
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
say() {
echo >&2 "$@"
}
format_haskell() {
local -r dir="$1"
say "Formatting $dir"
find "$dir" -type f -name '*.cabal' -print0 |
xargs -0 cabal-fmt --inplace --indent=2
find "$dir" -type f -name '*.hs' -print0 |
xargs -0 ormolu --mode=inplace -o '-XPatternSynonyms' -o '-XTypeApplications'
}
# Export the functions for use in GNU parallel.
export -f say
export -f format_haskell
# Whether include generated code in the formatting run.
all="false"
case "${1:-}" in
--all)
all="true"
;;
esac
targets=(
lib/gogol
lib/gogol-core
examples
)
if [ "$all" = "true" ]; then
targets+=(lib/services/gogol-*)
fi
say "Formatting shell"
find scripts -type f -print0 |
xargs -0 shfmt -s -i 2 -ln bash -w
say "Formatting nix"
find . -type f -name '*.nix' -print0 |
xargs -0 nixpkgs-fmt
say "Formatting haskell"
# Run the format and copy/replace steps in parallel.
printf '%s\n' "${targets[@]}" |
parallel --halt-on-error 2 format_haskell