1
1
mirror of https://github.com/nmattia/niv.git synced 2024-11-25 09:56:49 +03:00
niv/script/fmt
Nicolas Mattia de5a4e7d01
Update devshell (#367)
* Update devshell

Update nixpkgs and simplify devshell

* Run ormolu

* Fixups

* Format nix files

* Update sources
2023-03-11 22:16:53 +01:00

63 lines
1.3 KiB
Plaintext
Executable File

#!/usr/bin/env nix-shell
#!nix-shell -i bash
#!nix-shell -I nixpkgs=./nix
#!nix-shell -p ormolu
#!nix-shell -p glibcLocales
#!nix-shell --keep GITHUB_TOKEN
###
### fmt - Format Haskell files with Ormolu
###
### Usage:
### fmt [-c|--check]
###
### Options:
### -c,--check Only check formatting, don't change files
set -euo pipefail
help() {
sed -rn 's/^### ?//;T;p' "$0"
}
fmt() {
local mode="$1"
command -v ormolu >/dev/null 2>&1 || {
echo >&2 "error: ormolu not found. run this in niv's nix-shell"
exit 1
}
needs_formatting=( )
for f in $(find . -name '*.hs')
do
echo "checking: $f"
if ! ormolu --no-cabal --mode "$mode" "$f"; then
needs_formatting+=( "$f" )
fi
done
if [ ${#needs_formatting[@]} -eq 0 ]; then
echo All files checked for formatting
else
echo The following files need formatting:
for i in "${needs_formatting[@]}"; do
echo " - $i"
done
if [ "$mode" == "check" ]; then
exit 1
fi
echo "Please run ./script/fmt"
fi
}
if [ "$#" == "0" ]; then
fmt "inplace"
elif [ "$1" == "-c" ] || [ "$1" == "--check" ]; then
fmt "check"
elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
help
exit 0
else
help
exit 1
fi