forked from brendanhay/gogol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
format
executable file
·61 lines (43 loc) · 1.02 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
61
#!/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=(
gogol
core
gen
examples
)
if [ "$all" = "true" ]; then
targets+=(gogol-*)
fi
say "Formatting shell"
find scripts gen/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