From b8e4f1231314d42b09015f4856e15e98d3f2457c Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Wed, 17 Jul 2024 18:05:17 +0200 Subject: [PATCH] Simplify tool checking and improve arg checking --- scripts/devshell/prettify | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/scripts/devshell/prettify b/scripts/devshell/prettify index 89f4fb6ce0..60db957899 100755 --- a/scripts/devshell/prettify +++ b/scripts/devshell/prettify @@ -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) @@ -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!"