From 4722e36c7ee7d672779a0757e89d711b2636d492 Mon Sep 17 00:00:00 2001 From: "tan.nguyen" Date: Wed, 6 Mar 2024 16:14:21 +0700 Subject: [PATCH] Enable debug for gitwrapper. --- src/Artifact.php | 9 --------- src/Commands/ArtifactCommand.php | 32 +++++++++++++------------------- src/app.php | 6 +----- 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/Artifact.php b/src/Artifact.php index e5e4f2e..688cb84 100644 --- a/src/Artifact.php +++ b/src/Artifact.php @@ -4,11 +4,7 @@ namespace DrevOps\GitArtifact; -use GitWrapper\EventSubscriber\GitLoggerEventSubscriber; use GitWrapper\GitWrapper; -use Monolog\Handler\StreamHandler; -use Monolog\Level; -use Monolog\Logger; use SplFileInfo; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; @@ -143,11 +139,6 @@ public function __construct( ) { $this->fsFileSystem = $fsFileSystem; $this->gitWrapper = $gitWrapper; - if ($this->isDebug()) { - $logger = new Logger('git'); - $logger->pushHandler(new StreamHandler('php://stdout', Level::Debug)); - $this->gitWrapper->addLoggerEventSubscriber(new GitLoggerEventSubscriber($logger)); - } } /** diff --git a/src/Commands/ArtifactCommand.php b/src/Commands/ArtifactCommand.php index 9c7b88a..77276fd 100644 --- a/src/Commands/ArtifactCommand.php +++ b/src/Commands/ArtifactCommand.php @@ -5,7 +5,11 @@ namespace DrevOps\GitArtifact\Commands; use DrevOps\GitArtifact\Artifact; +use GitWrapper\EventSubscriber\GitLoggerEventSubscriber; use GitWrapper\GitWrapper; +use Monolog\Handler\StreamHandler; +use Monolog\Level; +use Monolog\Logger; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -19,24 +23,6 @@ class ArtifactCommand extends Command { - /** - * Construct for command. - * - * @param GitWrapper $gitWrapper - * Git wrapper. - * @param Filesystem $fileSystem - * File system. - * @param string|null $name - * Command name. - */ - public function __construct( - protected GitWrapper $gitWrapper, - protected Filesystem $fileSystem, - ?string $name = null, - ) { - parent::__construct($name); - } - /** * Configure command. */ @@ -107,7 +93,15 @@ protected function configure(): void */ protected function execute(InputInterface $input, OutputInterface $output): int { - $artifact = new Artifact($this->gitWrapper, $this->fileSystem, $output); + $gitWrapper = new GitWrapper(); + $optionDebug = $input->getOption('debug'); + if (($optionDebug || $output->isDebug())) { + $logger = new Logger('git'); + $logger->pushHandler(new StreamHandler('php://stdout', Level::Debug)); + $gitWrapper->addLoggerEventSubscriber(new GitLoggerEventSubscriber($logger)); + } + $fileSystem = new Filesystem(); + $artifact = new Artifact($gitWrapper, $fileSystem, $output); $remote = $input->getArgument('remote'); // @phpstan-ignore-next-line $artifact->artifact($remote, $input->getOptions()); diff --git a/src/app.php b/src/app.php index e329e40..e1eb894 100644 --- a/src/app.php +++ b/src/app.php @@ -5,15 +5,11 @@ * Main entry point for the application. */ -use GitWrapper\GitWrapper; use DrevOps\GitArtifact\Commands\ArtifactCommand; use Symfony\Component\Console\Application; -use Symfony\Component\Filesystem\Filesystem; $application = new Application(); -$gitWrapper = new GitWrapper(); -$fileSystem = new Filesystem(); -$command = new ArtifactCommand($gitWrapper, $fileSystem); +$command = new ArtifactCommand(); $application->add($command); $application->setDefaultCommand((string) $command->getName(), true); $application->run();