From 102c45da57c9c03ebd643f36c914222b2fda020f Mon Sep 17 00:00:00 2001 From: Andrew Masiye Date: Fri, 19 Dec 2025 15:22:02 +0200 Subject: [PATCH] feat(NewGame, ViewLog): improve command execution and error handling --- src/Commands/NewGame.php | 3 ++- src/Commands/ViewLog.php | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Commands/NewGame.php b/src/Commands/NewGame.php index 9bfef3d..c05be86 100644 --- a/src/Commands/NewGame.php +++ b/src/Commands/NewGame.php @@ -212,7 +212,8 @@ private function installDependencies(string $targetDirectory): void { // Install dependencies $this->output->writeln('Installing dependencies...', OutputInterface::VERBOSITY_VERBOSE); - if (false === `composer install --working-dir=$targetDirectory --ansi`) { + $installCommand = "composer install --working-dir=" . escapeshellarg($targetDirectory) . " --ansi"; + if (false === shell_exec($installCommand)) { throw new RuntimeException('Unable to install dependencies'); } } diff --git a/src/Commands/ViewLog.php b/src/Commands/ViewLog.php index f4afafe..6b21c07 100644 --- a/src/Commands/ViewLog.php +++ b/src/Commands/ViewLog.php @@ -55,10 +55,15 @@ public function execute(InputInterface $input, OutputInterface $output): int return Command::FAILURE; } - if (shell_exec('which multitail')) { - `multitail $logFilename`; - } else { - `tail $logFilename`; + $logCommand = "tail "; + + if (shell_exec("which multitail")) { + $logCommand = "multitail "; + } + + if (false === shell_exec($logCommand . escapeshellarg($logFilename))) { + $output->writeln("Failed to open log file $logFilename."); + return Command::FAILURE; } return Command::SUCCESS;