Skip to content

Commit

Permalink
Support --drall-group with site:aliases command
Browse files Browse the repository at this point in the history
  • Loading branch information
jigarius committed Mar 1, 2022
1 parent ed998e9 commit 01c8b8a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/Commands/ExecCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ protected function configure() {
NULL,
InputOption::VALUE_REQUIRED,
'Site group identifier.'

);

$this->addUsage('core:status');
Expand Down
11 changes: 10 additions & 1 deletion src/Commands/SiteAliasesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drall\Commands;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand All @@ -14,10 +15,18 @@ protected function configure() {
$this->setName('site:aliases');
$this->setAliases(['sa']);
$this->setDescription('Get a list of site aliases.');
$this->addOption(
'drall-group',
NULL,
InputOption::VALUE_REQUIRED,
'Site group identifier.'
);
}

protected function execute(InputInterface $input, OutputInterface $output) {
$aliases = $this->siteDetector()->getSiteAliases();
$aliases = $this->siteDetector()->getSiteAliases(
$input->getOption('drall-group')
);

if (count($aliases) === 0) {
$this->logger->warning('No site aliases found.');
Expand Down
29 changes: 19 additions & 10 deletions src/Services/SiteDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,22 @@ public function getSiteDirNames(string $group = NULL): array {
/**
* Get site aliases.
*
* @param string|null $group
* A site group, if any.
*
* @return Consolidation\SiteAlias\SiteAliasInterface[]
* Site aliases.
*/
public function getSiteAliases(): array {
return $this->siteAliasManager()->getMultiple();
public function getSiteAliases(string $group = NULL): array {
$result = $this->siteAliasManager()->getMultiple();

if (!$group) {
return $result;
}

return array_filter($result, function ($alias) use ($group) {
return in_array($group, $alias->get('drall.groups') ?? []);
});
}

/**
Expand All @@ -59,18 +70,16 @@ public function getSiteAliases(): array {
* If there are aliases like @foo.dev and @foo.prod, then @foo part is
* considered the site name.
*
* @param string|null $group
* A site group, if any.
*
* @return array
* An array of site alias names with the @ prefix.
*/
public function getSiteAliasNames(string $group = NULL): array {
$result = [];
foreach ($this->siteAliasManager()->getMultiple() as $siteAlias) {
if ($group && !in_array($group, $siteAlias->get('drall.groups') ?? [])) {
continue;
}

$result[] = explode('.', $siteAlias->name())[0];
}
$result = array_map(function ($siteAlias) {
return explode('.', $siteAlias->name())[0];
}, $this->getSiteAliases($group));
return array_unique(array_values($result));
}

Expand Down

0 comments on commit 01c8b8a

Please sign in to comment.