From 81853c5f1e8738c46ff3296fcb9ef7385158c9dd Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Mon, 15 Jul 2024 20:14:50 +0200 Subject: [PATCH] Check args better --- scripts/devshell/prettify | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/scripts/devshell/prettify b/scripts/devshell/prettify index 502a5be894..e18b0d8eee 100755 --- a/scripts/devshell/prettify +++ b/scripts/devshell/prettify @@ -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) @@ -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 @@ -64,7 +84,6 @@ do fi done - if [[ -z $files ]]; then echo "No files to format!" if [[ -z $1 ]]; then