diff --git a/composer.lock b/composer.lock index b741b22..d6e8dd3 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/src/Application.php b/src/Application.php index 0d28206..f10f183 100644 --- a/src/Application.php +++ b/src/Application.php @@ -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)); } } diff --git a/src/Command/Group/GroupCreateCommand.php b/src/Command/Group/GroupCreateCommand.php new file mode 100644 index 0000000..11a61f5 --- /dev/null +++ b/src/Command/Group/GroupCreateCommand.php @@ -0,0 +1,42 @@ +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; + } +} diff --git a/src/Command/Group/GroupQueryCommand.php b/src/Command/Group/GroupQueryCommand.php new file mode 100644 index 0000000..fa4b7d3 --- /dev/null +++ b/src/Command/Group/GroupQueryCommand.php @@ -0,0 +1,49 @@ +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,"_") + ? "%{$len}s: %s" + : "%{$len}s: %s", + $k, json_encode($v) + ) + ); + } + + return self::SUCCESS; + } +} diff --git a/src/Command/Group/GroupSetCommand.php b/src/Command/Group/GroupSetCommand.php new file mode 100644 index 0000000..da54d67 --- /dev/null +++ b/src/Command/Group/GroupSetCommand.php @@ -0,0 +1,49 @@ +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,"_") + ? "%{$len}s: %s" + : "%{$len}s: %s", + $k, json_encode($v) + ) + ); + } + + return self::SUCCESS; + } +} diff --git a/src/Command/Group/GroupShowCommand.php b/src/Command/Group/GroupShowCommand.php index e96efd6..3cb8dde 100644 --- a/src/Command/Group/GroupShowCommand.php +++ b/src/Command/Group/GroupShowCommand.php @@ -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,"_") - ? "%{$len}s: %s" - : "%{$len}s: %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; } diff --git a/src/Command/Slot/SlotCreateCommand.php b/src/Command/Slot/SlotCreateCommand.php new file mode 100644 index 0000000..8bebab5 --- /dev/null +++ b/src/Command/Slot/SlotCreateCommand.php @@ -0,0 +1,40 @@ +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; + } +}