Skip to content

Commit

Permalink
Enable debug for gitwrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
tannguyen04 committed Mar 6, 2024
1 parent 96d183f commit 4722e36
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
9 changes: 0 additions & 9 deletions src/Artifact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

/**
Expand Down
32 changes: 13 additions & 19 deletions src/Commands/ArtifactCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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());
Expand Down
6 changes: 1 addition & 5 deletions src/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 4722e36

Please sign in to comment.