#!/bin/bash -e
if [ "$1" == "-b" ]
then stack --stack-yaml stack.tools.yaml install --no-test --no-bench --no-haddock fourmolu
fi

INSTALL=`stack --stack-yaml stack.tools.yaml path --local-bin`
for f in `find -name '*.hs' -not -path '*.stack-work/*' -not -path '*/dist/*' | grep -xvf .format.ignore`
do $INSTALL/fourmolu -i -o -XPatternSynonyms $f || exit
done
