2025-03-13 22:29:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SlotDb\Cli\Command\Group;
|
|
|
|
|
|
|
|
use SlotDb\Client\SlotDbClient;
|
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Helper\Table;
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
#[AsCommand(name:"group:find", aliases:[ "groups" ], description:"Find all groups")]
|
|
|
|
class GroupFindCommand extends Command
|
|
|
|
{
|
|
|
|
public function __construct(
|
|
|
|
private readonly SlotDbClient $client
|
|
|
|
)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
{
|
|
|
|
|
|
|
|
$groups = $this->client->findGroups();
|
|
|
|
|
2025-03-14 22:57:35 +01:00
|
|
|
$keys = [];
|
|
|
|
foreach ($groups as $group) {
|
|
|
|
$keys = array_merge($keys, array_keys($group));
|
|
|
|
}
|
|
|
|
$keys = array_unique($keys);
|
|
|
|
|
|
|
|
$table = new Table($output);
|
|
|
|
$table->setHeaders($keys);
|
|
|
|
$table->setStyle('box');
|
|
|
|
foreach ($groups as $group) {
|
|
|
|
$row = [];
|
|
|
|
foreach ($keys as $key) {
|
|
|
|
$row[] = isset($group[$key]) ? json_encode($group[$key]) : null;
|
|
|
|
}
|
|
|
|
$table->addRow($row);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table->render();
|
2025-03-13 22:29:05 +01:00
|
|
|
|
|
|
|
return self::SUCCESS;
|
|
|
|
}
|
|
|
|
}
|