54 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace NoccyLabs\Serverctl\Commands;
 | 
						|
 | 
						|
use Symfony\Component\Console\Attribute\AsCommand;
 | 
						|
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:"start", description:"Start a service")]
 | 
						|
class StartCommand extends Command
 | 
						|
{
 | 
						|
    
 | 
						|
    protected function configure()
 | 
						|
    {
 | 
						|
        $this->addOption("instance", "i", InputOption::VALUE_REQUIRED, "Specify the instance name", "default");
 | 
						|
        $this->addOption("portoffset", "p", InputOption::VALUE_REQUIRED, "Offset port numbers by value", 0);
 | 
						|
        $this->addArgument("service", InputArgument::REQUIRED, "The service name");
 | 
						|
    }
 | 
						|
 | 
						|
    protected function execute(InputInterface $input, OutputInterface $output)
 | 
						|
    {
 | 
						|
        $serviceRegistry = $this->getServiceRegistry();
 | 
						|
        $containerManager = $this->getContainerManager();
 | 
						|
 | 
						|
 | 
						|
        $serviceName = $input->getArgument("service");
 | 
						|
 | 
						|
        $serviceInfo = $serviceRegistry->findServiceByName($serviceName);
 | 
						|
        if (!$serviceInfo) {
 | 
						|
            $output->writeln("<error>No such service in registry</>");
 | 
						|
            return self::FAILURE;
 | 
						|
        }
 | 
						|
        $instanceName = $input->getOption("instance");
 | 
						|
 | 
						|
        $options = [
 | 
						|
            'name' => $instanceName,
 | 
						|
            'portoffset' => $input->getOption("portoffset")
 | 
						|
        ];
 | 
						|
 | 
						|
        $output->write("Starting...\r");
 | 
						|
 | 
						|
        $info = $containerManager->startService($serviceInfo, $options);
 | 
						|
 | 
						|
        $output->writeln("Started <fg=cyan;options=bold>{$serviceName}</>[<fg=cyan>{$instanceName}</>]");
 | 
						|
        foreach ($info['ports'] as $info=>$port) {
 | 
						|
            $output->writeln("  <info>{$info}</>: <comment>{$port}</comment>");
 | 
						|
        }
 | 
						|
 | 
						|
        return self::SUCCESS;
 | 
						|
    }
 | 
						|
}
 |