Files
slotdb-cli/src/Command/Group/GroupQueryCommand.php

50 lines
1.4 KiB
PHP
Raw Normal View History

2025-03-14 01:38:18 +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: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;
}
}