From 5b00c3cc92bd16ebef0281ab39dccead9ff75463 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Tue, 27 Jul 2021 08:10:40 -0400 Subject: [PATCH] [minor] init improvements: - show composer output if verbose (-v) (closes #2) - throw exception if process fails --- src/InitCommand.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/InitCommand.php b/src/InitCommand.php index 3295462..25b30e4 100644 --- a/src/InitCommand.php +++ b/src/InitCommand.php @@ -42,19 +42,28 @@ protected function execute(InputInterface $input, OutputInterface $output) (new Filesystem())->remove($this->getDocumentRoot()); - $io->comment('Downloading latest version of phpMyAdmin...'); - $package = 'phpmyadmin/phpmyadmin'; if ($version) { $package .= ':'.$version; } - (new Process(['composer', 'create-project', $package, '.phpmyadmin'], $this->getHomeDir())) + $io->comment(\sprintf('Downloading phpMyAdmin %s...', $version ?: 'latest')); + + $process = (new Process(['composer', 'create-project', $package, '.phpmyadmin'], $this->getHomeDir())) ->setTimeout(null) - ->run() ; + $process->run(function($type, $buffer) use ($io) { + if ($io->isVerbose()) { + $io->writeln($buffer); + } + }); + + if (!$process->isSuccessful()) { + throw new \RuntimeException($process->getErrorOutput()); + } + $io->comment('Generating config.inc.php'); $config = \file_get_contents(__DIR__.'/../resources/config.inc.template'); \file_put_contents($this->getDocumentRoot().'/config.inc.php', \strtr($config, [