Skip to content

Commit

Permalink
Check args better
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Jul 15, 2024
1 parent 11ba9ce commit 81853c5
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions scripts/devshell/prettify
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ run_format() {
fourmolu -q -i "$file"
stylish-haskell -i "$file"
fi

fi
done
}

flag_passed="true"

# Parse command line arguments
case $1 in
-t|--tracked)
Expand All @@ -50,9 +51,28 @@ case $1 in
;;
*)
files="$@"
flag_passed="false"
;;
esac

if [[ $flag_passed == "true" ]] && [[ $# -gt 1 ]]; then
echo "ERROR: only one flag is allowed!"
echo -e
show_help
exit 1
fi

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
Expand All @@ -64,7 +84,6 @@ do
fi
done


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

0 comments on commit 81853c5

Please sign in to comment.