50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
|
<?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:query", description:"Show group information")]
|
||
|
class GroupQueryCommand extends Command
|
||
|
{
|
||
|
public function __construct(
|
||
|
private readonly SlotDbClient $client
|
||
|
)
|
||
|
{
|
||
|
parent::__construct();
|
||
|
}
|
||
|
|
||
|
protected function configure()
|
||
|
{
|
||
|
$this->addArgument("group", InputArgument::REQUIRED, "Group to display");
|
||
|
}
|
||
|
|
||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||
|
{
|
||
|
$groupId = $input->getArgument("group");
|
||
|
|
||
|
$group = $this->client->queryGroup($groupId);
|
||
|
|
||
|
$len = 2 + max(array_map(mb_strlen(...), array_keys($group)));
|
||
|
|
||
|
foreach ($group as $k=>$v) {
|
||
|
$output->writeln(
|
||
|
sprintf(
|
||
|
str_starts_with($k,"_")
|
||
|
? "<fg=green>%{$len}s</>: <fg=gray>%s</>"
|
||
|
: "<fg=green;options=bold>%{$len}s</>: <fg=yellow>%s</>",
|
||
|
$k, json_encode($v)
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return self::SUCCESS;
|
||
|
}
|
||
|
}
|