Skip to content

Commit

Permalink
CLI-1407: Add self:status command
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Oct 1, 2024
1 parent 8c65600 commit a1b0c01
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
34 changes: 34 additions & 0 deletions src/Command/Self/SelfStatusCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Acquia\Cli\Command\Self;

use Acquia\Cli\Command\CommandBase;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'self:status')]

final class SelfStatusCommand extends CommandBase
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
$table = new Table($output);
$table->setStyle('borderless');
$table->setHeaders(['Property', 'Value']);
$table->addRow(['Version', $this->getApplication()->getVersion()]);
$table->addRow(['Cloud datastore', $this->datastoreCloud->filepath]);
$table->addRow(['ACLI datastore', $this->datastoreAcli->filepath]);
$table->addRow(['Telemetry enabled', var_export($this->telemetryHelper->telemetryEnabled(), true)]);
$table->addRow(['User ID', $this->telemetryHelper->getUserId()]);
foreach ($this->telemetryHelper->getTelemetryUserData() as $key => $value) {
$table->addRow([$key, $value]);
}
$table->render();
return Command::SUCCESS;
}
}
17 changes: 10 additions & 7 deletions src/Helpers/TelemetryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public function initializeBugsnag(): void
if (empty($this->bugSnagKey)) {
return;
}
$sendTelemetry = $this->datastoreCloud->get(DataStoreContract::SEND_TELEMETRY);
if ($sendTelemetry === false) {
if (!$this->telemetryEnabled()) {
return;
}
// It's safe-ish to make this key public.
Expand Down Expand Up @@ -89,11 +88,10 @@ public function initializeAmplitude(): void
if (empty($this->amplitudeKey)) {
return;
}
$sendTelemetry = $this->datastoreCloud->get(DataStoreContract::SEND_TELEMETRY);
$amplitude = Amplitude::getInstance();
$amplitude->setOptOut($sendTelemetry === false);
$amplitude->setOptOut($this->telemetryEnabled());

if ($sendTelemetry === false) {
if (!$this->telemetryEnabled()) {
return;
}
try {
Expand All @@ -109,6 +107,11 @@ public function initializeAmplitude(): void
}
}

public function telemetryEnabled(): bool
{
return (bool) $this->datastoreCloud->get(DataStoreContract::SEND_TELEMETRY);
}

/**
* @param string $ah_env
* Environment name from AH_ENV.
Expand Down Expand Up @@ -140,7 +143,7 @@ public static function normalizeAhEnv(string $ah_env): string
*
* @return array<mixed> Telemetry user data.
*/
private function getTelemetryUserData(): array
public function getTelemetryUserData(): array
{
$data = [
'ah_app_uuid' => getenv('AH_APPLICATION_UUID'),
Expand Down Expand Up @@ -179,7 +182,7 @@ public static function getEnvironmentProvider(): ?string
return null;
}

private function getUserId(): ?string
public function getUserId(): ?string
{
$user = $this->getUserData();
if ($user && isset($user['uuid'])) {
Expand Down

0 comments on commit a1b0c01

Please sign in to comment.