Skip to content

Commit

Permalink
Per-command dependency injection (#1679)
Browse files Browse the repository at this point in the history
* Move LogstreamManager out of CommandBase

* Per-command dependency injection
  • Loading branch information
danepowell authored Feb 8, 2024
1 parent 6d963af commit 18a4a61
Show file tree
Hide file tree
Showing 25 changed files with 481 additions and 363 deletions.
8 changes: 0 additions & 8 deletions src/Command/Acsf/AcsfCommandFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
use Acquia\Cli\Helpers\LocalMachineHelper;
use Acquia\Cli\Helpers\SshHelper;
use Acquia\Cli\Helpers\TelemetryHelper;
use AcquiaLogstream\LogstreamManager;
use GuzzleHttp\Client;
use Psr\Log\LoggerInterface;

class AcsfCommandFactory implements CommandFactoryInterface {
Expand All @@ -26,11 +24,9 @@ public function __construct(
private TelemetryHelper $telemetryHelper,
private string $projectDir,
private AcsfClientService $cloudApiClientService,
private LogstreamManager $logstreamManager,
private SshHelper $sshHelper,
private string $sshDir,
private LoggerInterface $logger,
private Client $httpClient
) {
}

Expand All @@ -43,11 +39,9 @@ public function createCommand(): AcsfApiBaseCommand {
$this->telemetryHelper,
$this->projectDir,
$this->cloudApiClientService,
$this->logstreamManager,
$this->sshHelper,
$this->sshDir,
$this->logger,
$this->httpClient
);
}

Expand All @@ -60,11 +54,9 @@ public function createListCommand(): AcsfListCommand {
$this->telemetryHelper,
$this->projectDir,
$this->cloudApiClientService,
$this->logstreamManager,
$this->sshHelper,
$this->sshDir,
$this->logger,
$this->httpClient
);
}

Expand Down
8 changes: 0 additions & 8 deletions src/Command/Api/ApiCommandFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
use Acquia\Cli\Helpers\LocalMachineHelper;
use Acquia\Cli\Helpers\SshHelper;
use Acquia\Cli\Helpers\TelemetryHelper;
use AcquiaLogstream\LogstreamManager;
use GuzzleHttp\Client;
use Psr\Log\LoggerInterface;

class ApiCommandFactory implements CommandFactoryInterface {
Expand All @@ -26,11 +24,9 @@ public function __construct(
private TelemetryHelper $telemetryHelper,
private string $projectDir,
private ClientService $cloudApiClientService,
private LogstreamManager $logstreamManager,
private SshHelper $sshHelper,
private string $sshDir,
private LoggerInterface $logger,
private Client $httpClient
) {
}

Expand All @@ -43,11 +39,9 @@ public function createCommand(): ApiBaseCommand {
$this->telemetryHelper,
$this->projectDir,
$this->cloudApiClientService,
$this->logstreamManager,
$this->sshHelper,
$this->sshDir,
$this->logger,
$this->httpClient
);
}

Expand All @@ -60,11 +54,9 @@ public function createListCommand(): ApiListCommand {
$this->telemetryHelper,
$this->projectDir,
$this->cloudApiClientService,
$this->logstreamManager,
$this->sshHelper,
$this->sshDir,
$this->logger,
$this->httpClient
);
}

Expand Down
25 changes: 25 additions & 0 deletions src/Command/App/LogTailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@

namespace Acquia\Cli\Command\App;

use Acquia\Cli\ApiCredentialsInterface;
use Acquia\Cli\Attribute\RequireAuth;
use Acquia\Cli\CloudApi\ClientService;
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\DataStore\AcquiaCliDatastore;
use Acquia\Cli\DataStore\CloudDataStore;
use Acquia\Cli\Helpers\LocalMachineHelper;
use Acquia\Cli\Helpers\SshHelper;
use Acquia\Cli\Helpers\TelemetryHelper;
use AcquiaCloudApi\Endpoints\Logs;
use AcquiaLogstream\LogstreamManager;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -16,6 +25,22 @@
#[AsCommand(name: 'app:log:tail', description: 'Tail the logs from your environments', aliases: ['tail', 'log:tail'])]
final class LogTailCommand extends CommandBase {

public function __construct(
public LocalMachineHelper $localMachineHelper,
protected CloudDataStore $datastoreCloud,
protected AcquiaCliDatastore $datastoreAcli,
protected ApiCredentialsInterface $cloudCredentials,
protected TelemetryHelper $telemetryHelper,
protected string $projectDir,
protected ClientService $cloudApiClientService,
public SshHelper $sshHelper,
protected string $sshDir,
LoggerInterface $logger,
protected LogstreamManager $logstreamManager,
) {
parent::__construct($this->localMachineHelper, $this->datastoreCloud, $this->datastoreAcli, $this->cloudCredentials, $this->telemetryHelper, $this->projectDir, $this->cloudApiClientService, $this->sshHelper, $this->sshDir, $logger);
}

protected function configure(): void {
$this
->acceptEnvironmentId();
Expand Down
Loading

0 comments on commit 18a4a61

Please sign in to comment.