a8dee63ffe8839d3bcf1066f8359fa43caccf3f2

Author
Ryan Tvenge <ryan@hoverboardstudios.com>
Committer
Marc Cornellà <marc@mcornella.com>
Date

Message

feat(lando): bypass `lando` if command is not available in container (#11993)

Closes #11993

Diff

 1diff --git a/plugins/lando/lando.plugin.zsh b/plugins/lando/lando.plugin.zsh
 2index af53e7e5a9f417773b6ea907e1b9f4e6462b644a..b5fa800926e01acbf8b9ed305ec1ad700c2751cd 100644
 3--- a/plugins/lando/lando.plugin.zsh
 4+++ b/plugins/lando/lando.plugin.zsh
 5@@ -11,15 +11,23 @@ function artisan \
 6          php \
 7          wp \
 8          yarn {
 9-  if checkForLandoFile; then
10-    lando "$0" "$@"
11+  # If the lando task is available in `lando --help`, then it means:
12+  #
13+  # 1. `lando` is in a project with a `.lando.yml` file.
14+  # 2. The lando task is available for lando, based on the .lando.yml config file.
15+  #
16+  # This has a penalty of about 250ms, so we still want to check if the lando file
17+  # exists before, which is the fast path. If it exists, checking help output is
18+  # still faster than running the command and failing.
19+  if _lando_file_exists && lando --help 2>&1 | command grep -Eq "^ +lando $0 "; then
20+    command lando "$0" "$@"
21   else
22     command "$0" "$@"
23   fi
24 }
25 
26 # Check for the file in the current and parent directories.
27-checkForLandoFile() {
28+_lando_file_exists() {
29   # Only bother checking for lando within the Sites directory.
30   if [[ "$PWD/" != "$LANDO_ZSH_SITES_DIRECTORY"/* ]]; then
31     # Not within $LANDO_ZSH_SITES_DIRECTORY
32@@ -38,4 +46,4 @@ checkForLandoFile() {
33   # Could not find $LANDO_ZSH_CONFIG_FILE in the current directory
34   # or in any of its parents up to $LANDO_ZSH_SITES_DIRECTORY.
35   return 1
36-}
37+}