From 66e324445215697d84569bdfaed36d8002edd83d Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen.haas@lakedrops.com>
Date: Fri, 29 Jul 2022 14:55:12 +0200
Subject: [PATCH] drupal/development/eca#1 Improve parsing of CLI arguments so
 that the drush command gets recognized even if options were provided before

---
 bin/drush | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/bin/drush b/bin/drush
index 20f0741..402f98a 100755
--- a/bin/drush
+++ b/bin/drush
@@ -4,23 +4,35 @@ function setPermissions {
   sudo chmod -R g+w .
 }
 
+MODE=default
 FLAG=
 if [[ "$1" == "-T" ]]; then
   FLAG=-T
   shift
 fi
-if [[ "$1" == "si" ]] || [[ "$1" == "sin" ]] || [[ "$1" == "site-install" ]]; then
-  FLAG="$FLAG -e L3D_DISABLE_REDIS=yes"
-fi
+for arg in "$@"; do
+  case "$arg" in
+    si|sin|site-install|site:install)
+      FLAG="$FLAG -e L3D_DISABLE_REDIS=yes"
+      MODE=site-install
+      break
+      ;;
+    gen|generate)
+      MODE=generator
+      break
+      ;;
+  esac
+done
+
 docker compose exec $FLAG ${LAKEDROPS_DEV_DC_OPTIONS} php drush "$@"
 EC=$?
 
-if [[ "$1" == "si" ]] || [[ "$1" == "sin" ]] || [[ "$1" == "site-install" ]]; then
+if [[ "$MODE" == "site-install" ]]; then
   if [[ -f web/modules/contrib/redis/example.services.yml ]]; then
     docker compose exec $FLAG ${LAKEDROPS_DEV_DC_OPTIONS} php drush -y en redis
   fi
 fi
-if [[ "$1" == "gen" ]] || [[ "$1" == "generate" ]]; then
+if [[ "$MODE" == "generator" ]]; then
   setPermissions
 fi
 
-- 
GitLab