Skip to content

Commit

Permalink
Simplify tool checking and improve arg checking
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Jul 17, 2024
1 parent 4805678 commit b8e4f12
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions scripts/devshell/prettify
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ run_format() {
fourmolu -q -i "$top_level/$file"
stylish-haskell -i "$top_level/$file"
fi

fi
done
}

flag_passed="true"

# Parse command line arguments
case $1 in
-t|--tracked)
Expand All @@ -55,25 +56,38 @@ case $1 in
;;
*)
files="$@"
flag_passed="false"
;;
esac

if !(which stylish-haskell > /dev/null 2>&1); then
echo "ERROR: stylish-haskell is not available!"
echo -e
echo "Try entering the development shell with:"
echo " nix develop"
exit 1
if [[ $flag_passed == "true" ]] && [[ $# -gt 1 ]]; then
echo "ERROR: only one flag is allowed!"
echo -e
show_help
exit 1
fi

if !(which fourmolu > /dev/null 2>&1); then
echo "ERROR: fourmolu is not available!"
for file in $files; do
if [[ ! -a $file ]]; then
echo "ERROR: $file does not exist"
exit 1
if ![[ -f $file ]]; then
echo "ERROR: $file is not a regular file"
exit
fi
fi
done

for tool in stylish-haskell fourmolu
do
if !(which $tool > /dev/null 2>&1); then
echo "ERROR: $tool is not available!"
echo -e
echo "Try entering the development shell with:"
echo " nix develop"
exit 1
fi

fi
done

if [[ -z $files ]]; then
echo "No files to format!"
Expand Down

0 comments on commit b8e4f12

Please sign in to comment.