|
2 | 2 |
|
3 | 3 | set -euo pipefail
|
4 | 4 |
|
| 5 | +function usage { |
| 6 | + echo "Usage $(basename "$0") [-ch]" |
| 7 | + echo "Check files with 'stylish-haskell'; by default check all files." |
| 8 | + echo |
| 9 | + echo " -u only check files uncommitted" |
| 10 | + echo " -c only check files committed in HEAD" |
| 11 | + echo " -h this help message" |
| 12 | + exit |
| 13 | +} |
| 14 | + |
5 | 15 | export LC_ALL=C.UTF-8
|
| 16 | + |
| 17 | +STYLISH_HASKELL_ARGS="-c .stylish-haskell-network.yaml -i" |
| 18 | + |
| 19 | +optstring=":uch" |
| 20 | +while getopts ${optstring} arg; do |
| 21 | + case ${arg} in |
| 22 | + h) |
| 23 | + usage; |
| 24 | + exit 0 |
| 25 | + ;; |
| 26 | + c) |
| 27 | + PATHS=$(git show --pretty='' --name-only HEAD) |
| 28 | + for path in $PATHS; do |
| 29 | + if [ "${path##*.}" == "hs" ]; then |
| 30 | + if grep -qE '^#' $path; then |
| 31 | + echo "$path contains CPP. Skipping." |
| 32 | + else |
| 33 | + echo $path |
| 34 | + stylish-haskell $STYLISH_HASKELL_ARGS $path |
| 35 | + fi |
| 36 | + fi |
| 37 | + done |
| 38 | + exit 0 |
| 39 | + ;; |
| 40 | + u) |
| 41 | + PATHS=$(git diff --name-only HEAD) |
| 42 | + for path in $PATHS; do |
| 43 | + if [ "${path##*.}" == "hs" ]; then |
| 44 | + if grep -qE '^#' $path; then |
| 45 | + echo "$path contains CPP. Skipping." |
| 46 | + else |
| 47 | + echo $path |
| 48 | + stylish-haskell $STYLISH_HASKELL_ARGS $path |
| 49 | + fi |
| 50 | + fi |
| 51 | + done |
| 52 | + exit 0 |
| 53 | + ;; |
| 54 | + ?) |
| 55 | + echo "Invalid argument ${arg}" |
| 56 | + exit 1 |
| 57 | + ;; |
| 58 | + esac |
| 59 | +done |
| 60 | + |
6 | 61 | # TODO CPP pragmas in export lists are not supported by stylish-haskell
|
7 |
| -fd . './quickcheck-monoids' -e hs --ignore-file ./scripts/ci/check-stylish-ignore -X stylish-haskell -c .stylish-haskell-network.yaml -i |
8 |
| -fd . './network-mux' -e hs --ignore-file ./scripts/ci/check-stylish-ignore -X stylish-haskell -c .stylish-haskell-network.yaml -i |
9 |
| -fd . './ouroboros-network-api' -e hs --ignore-file ./scripts/ci/check-stylish-ignore -X stylish-haskell -c .stylish-haskell-network.yaml -i |
10 |
| -fd . './ouroboros-network-framework' -e hs --ignore-file ./scripts/ci/check-stylish-ignore -X stylish-haskell -c .stylish-haskell-network.yaml -i |
11 |
| -fd . './ouroboros-network-mock' -e hs --ignore-file ./scripts/ci/check-stylish-ignore -X stylish-haskell -c .stylish-haskell-network.yaml -i |
12 |
| -fd . './ouroboros-network-protocols' -e hs --ignore-file ./scripts/ci/check-stylish-ignore -X stylish-haskell -c .stylish-haskell-network.yaml -i |
13 |
| -fd . './ouroboros-network' -e hs --ignore-file ./scripts/ci/check-stylish-ignore -X stylish-haskell -c .stylish-haskell-network.yaml -i |
14 |
| -fd . './cardano-client' -e hs --ignore-file ./scripts/ci/check-stylish-ignore -X stylish-haskell -c .stylish-haskell-network.yaml -i |
| 62 | +FD_OPTS="-e hs --ignore-file ./scripts/ci/check-stylish-ignore -X stylish-haskell $STYLISH_HASKELL_ARGS" |
| 63 | + |
| 64 | +fd . './quickcheck-monoids' $FD_OPTS |
| 65 | +fd . './network-mux' $FD_OPTS |
| 66 | +fd . './ouroboros-network-api' $FD_OPTS |
| 67 | +fd . './ouroboros-network-framework' $FD_OPTS |
| 68 | +fd . './ouroboros-network-mock' $FD_OPTS |
| 69 | +fd . './ouroboros-network-protocols' $FD_OPTS |
| 70 | +fd . './ouroboros-network' $FD_OPTS |
| 71 | +fd . './cardano-client' $FD_OPTS |
0 commit comments