Skip to content

Commit

Permalink
chore(dev): change expanded format (#6470)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer authored Oct 9, 2023
1 parent 5bc79c6 commit af7bada
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
68 changes: 36 additions & 32 deletions dev/src/Command/ComponentInfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,49 +141,53 @@ protected function execute(InputInterface $input, OutputInterface $output)
private function getComponentDetails(Component $component, array $requestedFields, bool $expanded): array
{
$rows = [];
// use "array_intersect_key" to filter out fields that were not requested.
// use "array_replace" to sort the fields in the order they were requested.
$details = array_replace($requestedFields, array_intersect_key([
'name' => $component->getName(),
'package_name' => $component->getPackageName(),
'package_version' => $component->getPackageVersion(),
'api_versions' => $expanded ? '' : implode("\n", $component->getApiVersions()),
'release_level' => $component->getReleaseLevel(),
'migration' => $expanded ? '' : implode("\n", $component->getMigrationStatuses()),
'php_namespaces' => implode("\n", array_keys($component->getNamespaces())),
'github_repo' => $component->getRepoName(),
'proto' => $expanded ? '' : implode("\n", $component->getProtoPackages()),
'service_address' => $expanded ? '' : implode("\n", $component->getServiceAddresses()),
'shortname' => $expanded ? '' : implode("\n", $component->getApiShortnames()),
'description' => $component->getDescription(),
], $requestedFields));

if (array_key_exists('available_api_versions', $requestedFields)) {
$details['available_api_versions'] = $this->getAvailableApiVersions($component);
}

$rows[] = $details;

if ($expanded) {
foreach ($component->getComponentPackages() as $pkg) {
$availableApiVersions = '';
if (array_key_exists('available_api_versions', $requestedFields)) {
$availableApiVersions = $this->getAvailableApiVersions($component);
}
// use "array_intersect_key" to filter out fields that were not requested.
// use "array_replace" to sort the fields in the order they were requested.
$rows[] = array_replace($requestedFields, array_intersect_key([
'name' => " " . $pkg->getName(),
'package_name' => '', // defined by component
'package_version' => '', // defined by component
'api_versions' => '', // included in "name"
'release_level' => '', // defined by component
'name' => $component->getName() . "\\" . $pkg->getName(),
'package_name' => $component->getPackageName(),
'package_version' => $component->getPackageVersion(),
'api_versions' => $pkg->getName(),
'release_level' => $component->getReleaseLevel(),
'migration' => $pkg->getMigrationStatus(),
'php_namespaces' => '', // defined by component
'github_repo' => '', // defined by component
'php_namespaces' => implode("\n", array_keys($component->getNamespaces())),
'github_repo' => $component->getRepoName(),
'proto' => $pkg->getProtoPackage(),
'service_address' => $pkg->getServiceAddress(),
'shortname' => $pkg->getApiShortname(),
'description' => '', // defined by component
'available_api_versions' => '', // defined by component
'description' => $component->getDescription(),
'available_api_versions' => $availableApiVersions,
], $requestedFields));
}
} else {
// use "array_intersect_key" to filter out fields that were not requested.
// use "array_replace" to sort the fields in the order they were requested.
$details = array_replace($requestedFields, array_intersect_key([
'name' => $component->getName(),
'package_name' => $component->getPackageName(),
'package_version' => $component->getPackageVersion(),
'api_versions' => implode("\n", $component->getApiVersions()),
'release_level' => $component->getReleaseLevel(),
'migration' => implode("\n", $component->getMigrationStatuses()),
'php_namespaces' => implode("\n", array_keys($component->getNamespaces())),
'github_repo' => $component->getRepoName(),
'proto' => implode("\n", $component->getProtoPackages()),
'service_address' => implode("\n", $component->getServiceAddresses()),
'shortname' => implode("\n", $component->getApiShortnames()),
'description' => $component->getDescription(),
], $requestedFields));

if (array_key_exists('available_api_versions', $requestedFields)) {
$details['available_api_versions'] = $this->getAvailableApiVersions($component);
}

$rows[] = $details;
}

return $rows;
Expand Down
9 changes: 7 additions & 2 deletions dev/src/ComponentPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class ComponentPackage
\* Updates to the above are reflected here through a refresh process#';
private string $path;

private const MIGRATION_V1 = 'v1';
private const MIGRATION_V2 = 'v2';
private const MIGRATION_V1_AND_V2 = 'v1 and v2';
private const MIGRATION_NA = 'n/a';

public function __construct(private Component $component, private string $name)
{
$this->path = $component->getPath() . '/src/' . $name;
Expand Down Expand Up @@ -62,9 +67,9 @@ public function getMigrationStatus()
$hasV1Clients = count($this->getV1GapicClientFiles()) > 0;
$hasV2Clients = count($this->getV2BaseClientFiles()) > 0;
if ($hasV1Clients) {
return $hasV2Clients ? 'v1+v2' : 'v1';
return $hasV2Clients ? self::MIGRATION_V1_AND_V2 : self::MIGRATION_V1;
}
return $hasV2Clients ? 'v2' : 'n/a';
return $hasV2Clients ? self::MIGRATION_V2 : self::MIGRATION_NA;
}

public function getServiceAddress(): string
Expand Down

0 comments on commit af7bada

Please sign in to comment.