Initial commit
This commit is contained in:
		
							
								
								
									
										39
									
								
								src/Commands/StopCommand.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/Commands/StopCommand.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
<?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:"stop", description:"Stop a running service")]
 | 
			
		||||
class StopCommand extends Command
 | 
			
		||||
{
 | 
			
		||||
    
 | 
			
		||||
    protected function configure()
 | 
			
		||||
    {
 | 
			
		||||
        $this->addOption("instance", "I", InputOption::VALUE_REQUIRED, "Specify the instance name", "default");
 | 
			
		||||
        $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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $containerManager->stopService($serviceInfo, $input->getOption("instance"));
 | 
			
		||||
 | 
			
		||||
        return self::SUCCESS;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user