54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace NoccyLabs\Serverctl\Commands;
|
|
|
|
use NoccyLabs\Spinner\Spinner;
|
|
use NoccyLabs\Spinner\Style\BrailleDotsStyle;
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Helper\Table;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
#[AsCommand(name:"status", description:"Show the running services")]
|
|
class StatusCommand extends Command
|
|
{
|
|
|
|
protected function configure()
|
|
{
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
/*
|
|
$spinner = new Spinner(style: BrailleDotsStyle::class, fps: 15);
|
|
|
|
$output->write(" Getting status\r");
|
|
for ($n = 0; $n < 250; $n++) {
|
|
if ($output->isDecorated()) $output->write("({$spinner})\r");
|
|
usleep(10000);
|
|
}
|
|
*/
|
|
|
|
$containerManager = $this->getContainerManager();
|
|
|
|
$table = new Table($output);
|
|
$table->setStyle('compact');
|
|
$table->setHeaders([ "Service", "Instance", "Purpose", "Port" ]);
|
|
|
|
$running = $containerManager->getRunningServices();
|
|
$s = 0;
|
|
foreach ($running as $service) {
|
|
$s++;
|
|
$i = 0;
|
|
foreach ($service['ports'] as $portInfo=>$portNumber) {
|
|
$table->addRow([ ($i==0)?$service['service']['name']:"", ($i==0)?$service['instance']:"", $portInfo, $portNumber ]);
|
|
$i++;
|
|
}
|
|
}
|
|
$table->render();
|
|
$output->writeln("<options=bold>{$s}</> running services.");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
} |