diff --git a/http-helper/Command.php b/http-helper/Command.php index 48b09bf6..32781d57 100644 --- a/http-helper/Command.php +++ b/http-helper/Command.php @@ -6,7 +6,6 @@ namespace Http; use Annotation\Inject; use Exception; -use Kiri\Abstracts\Input; use Kiri\Events\EventProvider; use Kiri\Exception\ConfigException; use Kiri\Exception\NotFindClassException; @@ -16,6 +15,7 @@ use Server\Events\OnBeforeWorkerStart; use Server\Events\OnWorkerStart; use Server\Worker\OnServerWorker; use Server\Worker\OnWorkerStart as WorkerDispatch; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -44,8 +44,8 @@ class Command extends \Symfony\Component\Console\Command\Command { $this->setName('sw:server') ->setDescription('server start|stop|reload|restart') - ->addOption('action') - ->addOption('daemon'); + ->addArgument('action', InputArgument::REQUIRED) + ->addArgument('daemon', InputArgument::OPTIONAL, '', 0); } @@ -58,19 +58,22 @@ class Command extends \Symfony\Component\Console\Command\Command * @throws ReflectionException * @throws Exception */ - public function execute(InputInterface $input, OutputInterface $output): string + public function execute(InputInterface $input, OutputInterface $output): int { $manager = Kiri::app()->getServer(); $manager->setDaemon($input->getArgument('daemon')); if (!in_array($input->getArgument('action'), self::ACTIONS)) { - return $output->write('I don\'t know what I want to do.'); + $output->write('I don\'t know what I want to do.'); + return 1; } if ($manager->isRunner() && $input->getArgument('action') == 'start') { - return $output->write('Service is running. Please use restart.'); + $output->write('Service is running. Please use restart.'); + return 1; } $manager->shutdown(); if ($input->getArgument('action') == 'stop') { - return $output->write('shutdown success'); + $output->write('shutdown success'); + return 1; } return $this->generate_runtime_builder($manager); } @@ -89,7 +92,9 @@ class Command extends \Symfony\Component\Console\Command\Command $this->eventProvider->on(OnBeforeWorkerStart::class, [di(OnServerWorker::class), 'setConfigure']); $this->eventProvider->on(OnWorkerStart::class, [di(WorkerDispatch::class), 'dispatch']); - return $manager->start(); + $manager->start(); + + return 0; } }