Add more group commands
This commit is contained in:
parent
8c5e962a55
commit
5247410218
4
composer.lock
generated
4
composer.lock
generated
@ -594,7 +594,7 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "../slotdb-client-php",
|
||||
"reference": "bee9457d9da382621e3cc99ffd4b75af443ad27b"
|
||||
"reference": "c85e36f1cb035b2f854bfe01b03da739d5decf66"
|
||||
},
|
||||
"require": {
|
||||
"psr/http-client": "^1.0"
|
||||
@ -620,7 +620,7 @@
|
||||
}
|
||||
],
|
||||
"description": "SlotDB PHP Client",
|
||||
"time": "2025-03-13T23:31:13+00:00"
|
||||
"time": "2025-03-14T00:36:19+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/console",
|
||||
|
@ -11,18 +11,24 @@ class Application extends \Symfony\Component\Console\Application
|
||||
{
|
||||
parent::__construct("slotcli", "0.0.0");
|
||||
|
||||
$baseUrl = getenv("SLOTCLI_SERVER") ?: "http://127.0.0.1:8080";
|
||||
|
||||
$psr = new Client();
|
||||
$client = new SlotDbClient($psr);
|
||||
$client = new SlotDbClient($psr, $baseUrl);
|
||||
|
||||
$this->add(new Command\ImportCommand());
|
||||
$this->add(new Command\ExportCommand());
|
||||
|
||||
$this->add(new Command\Slot\SlotCreateCommand($client));
|
||||
$this->add(new Command\Slot\SlotQueryCommand($client));
|
||||
$this->add(new Command\Slot\SlotFindCommand($client));
|
||||
$this->add(new Command\Slot\SlotSetCommand($client));
|
||||
|
||||
$this->add(new Command\Group\GroupCreateCommand($client));
|
||||
$this->add(new Command\Group\GroupFindCommand($client));
|
||||
$this->add(new Command\Group\GroupQueryCommand($client));
|
||||
$this->add(new Command\Group\GroupShowCommand($client));
|
||||
$this->add(new Command\Group\GroupSetCommand($client));
|
||||
}
|
||||
|
||||
}
|
||||
|
42
src/Command/Group/GroupCreateCommand.php
Normal file
42
src/Command/Group/GroupCreateCommand.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?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\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(name:"group:create", description:"Create a new group")]
|
||||
class GroupCreateCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SlotDbClient $client
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->addOption("name", "n", InputOption::VALUE_REQUIRED, "Set slot name")
|
||||
->addArgument("group", InputArgument::REQUIRED, "Group IP")
|
||||
->addArgument("properties", InputArgument::IS_ARRAY, "Properties to assign to the group")
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
|
||||
$groups = $this->client->findGroups();
|
||||
|
||||
var_dump($groups);
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
49
src/Command/Group/GroupQueryCommand.php
Normal file
49
src/Command/Group/GroupQueryCommand.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
49
src/Command/Group/GroupSetCommand.php
Normal file
49
src/Command/Group/GroupSetCommand.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?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:set", description:"Update group properties")]
|
||||
class GroupSetCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SlotDbClient $client
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->addArgument("group", InputArgument::REQUIRED, "Group to update");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -29,20 +29,26 @@ class GroupShowCommand extends Command
|
||||
{
|
||||
$groupId = $input->getArgument("group");
|
||||
|
||||
$group = $this->client->queryGroup($groupId);
|
||||
$slots = $this->client->queryGroupSlots($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)
|
||||
)
|
||||
);
|
||||
$keys = [];
|
||||
foreach ($slots as $slot) {
|
||||
$keys = array_merge($keys, array_keys($slot));
|
||||
}
|
||||
$keys = array_unique($keys);
|
||||
|
||||
$table = new Table($output);
|
||||
$table->setHeaders($keys);
|
||||
$table->setStyle('box');
|
||||
foreach ($slots as $slot) {
|
||||
$row = [];
|
||||
foreach ($keys as $key) {
|
||||
$row[] = isset($slot[$key]) ? json_encode($slot[$key]) : null;
|
||||
}
|
||||
$table->addRow($row);
|
||||
}
|
||||
|
||||
$table->render();
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
40
src/Command/Slot/SlotCreateCommand.php
Normal file
40
src/Command/Slot/SlotCreateCommand.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace SlotDb\Cli\Command\Slot;
|
||||
|
||||
use SlotDb\Client\SlotDbClient;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(name:"slot:create", description:"Create a new slot")]
|
||||
class SlotCreateCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SlotDbClient $client
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->addOption("name", "n", InputOption::VALUE_REQUIRED, "Set slot name")
|
||||
->addArgument("slot", InputArgument::REQUIRED, "Slot ID")
|
||||
->addArgument("properties", InputArgument::IS_ARRAY, "Properties to assign to the slot")
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
|
||||
// $slotId = $input->getArgument("slot");
|
||||
// $slot = $this->client->querySlot($slotId);
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user