From e8853b70e540f448e71a0bec75c4b929f5f51979 Mon Sep 17 00:00:00 2001 From: Hernold Koch Date: Fri, 10 May 2024 17:09:20 +0200 Subject: [PATCH 1/3] FIX 'which' check in 'sake' now works for aliases Improves on the current implementations since 'command' already only returns executable commands. Additionally, the success output of 'command' is not standardized and may contain additional information. Therefore, a 'test' if the result of 'command' is a valid executable file, may fail incorrectly. Now just relying on the standardized exit status of 'command -v'. --- sake | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sake b/sake index 3e1274d8cfb..8fb304783e0 100755 --- a/sake +++ b/sake @@ -9,10 +9,7 @@ Executes a SilverStripe command" exit 1 fi -if ! [ -x "$(command -v which)" ]; then - echo "Error: sake requires the 'which' command to operate." >&2 - exit 1 -fi +command -v which >/dev/null 2>&1 || { echo >&2 "Error: sake requires the 'which' command to operate."; exit 1; } # find the silverstripe installation, looking first at sake # bin location, but falling back to current directory From f4b8cc3efbc598886423cb6a7c11485692efa982 Mon Sep 17 00:00:00 2001 From: Hernold Koch Date: Fri, 17 May 2024 10:07:48 +0200 Subject: [PATCH 2/3] ENH Improved readability of sake's which check The previous implementation used '&&' piping wich is handled differently in PHP and Bash code and therefore, may be confusing to a PHP developer. I refactored the function to use a traditional if statement. --- sake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sake b/sake index 8fb304783e0..5b57ebdc250 100755 --- a/sake +++ b/sake @@ -9,7 +9,10 @@ Executes a SilverStripe command" exit 1 fi -command -v which >/dev/null 2>&1 || { echo >&2 "Error: sake requires the 'which' command to operate."; exit 1; } +if ! command -v which >/dev/null 2>&1; then + echo "Error: sake requires the 'which' command to operate." >&2 + exit 1 +fi # find the silverstripe installation, looking first at sake # bin location, but falling back to current directory From 01efd26a5f4ff93b81b814945953db977ceb7c23 Mon Sep 17 00:00:00 2001 From: Hernold Koch Date: Fri, 17 May 2024 10:53:09 +0200 Subject: [PATCH 3/3] ENH Improved readability of sake's which check Converted to 'if' to square bracket based testing to be in comply with the other 'if' statements in the script. Co-authored-by: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> --- sake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sake b/sake index 5b57ebdc250..65d9af3394a 100755 --- a/sake +++ b/sake @@ -9,7 +9,8 @@ Executes a SilverStripe command" exit 1 fi -if ! command -v which >/dev/null 2>&1; then +command -v which >/dev/null 2>&1 +if [ $? -ne 0 ]; then echo "Error: sake requires the 'which' command to operate." >&2 exit 1 fi