From 60afc284c696592278717076ba0482ff3ee75990 Mon Sep 17 00:00:00 2001 From: Yuvania Castillo <61019-Yuvania@users.noreply.drupalcode.org> Date: Wed, 31 Jul 2024 02:18:57 -0600 Subject: [PATCH] feat: Add support for passing unknown commands to Lando/DDEV --- src/FireApp.php | 57 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/FireApp.php b/src/FireApp.php index c7a91c3..4d3656d 100644 --- a/src/FireApp.php +++ b/src/FireApp.php @@ -95,10 +95,65 @@ public function __construct(Config $config, $classLoader, InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output */ public function run(InputInterface $input, OutputInterface $output) { - $status_code = $this->runner->run($input, $output, $this->application, $this->commandClasses); + $command = $input->getFirstArgument(); + + // If the command is a known FIRE command, run it, otherwise pass to Lando/DDEV. + $status_code = $this->isFireCommand($command) + ? $this->runner->run($input, $output, $this->application, $this->commandClasses) + : $this->passToLocalEnv($command, $input, $output); + return $status_code; } + /** + * Checks if the command is known to FIRE. + * + * @param string $command + * The command to check. + * + * @return bool + * TRUE if the command is known to FIRE, FALSE otherwise. + */ + private function isFireCommand($command) { + foreach ($this->commandClasses as $commandClass) { + if (strpos($commandClass, $command) !== false) { + return true; + } + } + return false; + } + + /** + * Passes the command to the local environment (Lando/DDEV). + * + * @param string $command + * The command to pass. + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Symfony\Component\Console\Output\OutputInterface $output + * + * @return int + * The exit code of the executed command. + */ + private function passToLocalEnv($command, InputInterface $input, OutputInterface $output) { + $env = $this->getLocalEnv(); + $args = array_slice($_SERVER['argv'], 2); // Skip 'fire' and the command itself. + $taskExec = null; + + switch ($env) { + case 'lando': + $taskExec = $this->taskExec('lando ' . $command)->args($args); + break; + case 'ddev': + $taskExec = $this->taskExec('ddev ' . $command)->args($args); + break; + default: + $output->writeln("Unknown local environment: $env"); + return 1; + } + + return $taskExec->run()->getExitCode(); + } + /** * Returns the local env (ddev, lando). */