change commands definition to attribute

This commit is contained in:
sunxyw
2022-12-17 21:53:08 +08:00
parent c6f877700e
commit 3806983bc2
11 changed files with 36 additions and 73 deletions

View File

@@ -5,18 +5,13 @@ declare(strict_types=1);
namespace ZM\Command\Server;
use Swoole\Process;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'server:reload', description: '重载服务器')]
class ServerReloadCommand extends ServerCommand
{
protected static $defaultName = 'server:reload';
protected function configure()
{
$this->setDescription('重载框架');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
parent::execute($input, $output);

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ZM\Command\Server;
use OneBot\Driver\Process\ProcessManager;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@@ -13,20 +14,20 @@ use ZM\Exception\ZMKnownException;
use ZM\Framework;
use ZM\Process\ProcessStateManager;
#[AsCommand(name: 'server:start', description: '启动服务器', aliases: ['server'])]
class ServerStartCommand extends ServerCommand
{
protected static $defaultName = 'server';
public static function exportOptionArray(): array
{
$cmd = new self();
$cmd->configure();
return array_map(function ($x) { return $x->getDefault(); }, $cmd->getDefinition()->getOptions());
return array_map(function ($x) {
return $x->getDefault();
}, $cmd->getDefinition()->getOptions());
}
protected function configure()
{
$this->setAliases(['server:start']);
$this->setDefinition([
new InputOption('config-dir', null, InputOption::VALUE_REQUIRED, '指定其他配置文件目录'),
new InputOption('driver', null, InputOption::VALUE_REQUIRED, '指定驱动类型'),
@@ -40,7 +41,6 @@ class ServerStartCommand extends ServerCommand
new InputOption('private-mode', null, null, '启动时隐藏MOTD和敏感信息'),
new InputOption('print-process-pid', null, null, '打印所有进程的PID'),
]);
$this->setDescription('Run zhamao-framework | 启动框架');
$this->setHelp('直接运行可以启动');
}

View File

@@ -4,18 +4,13 @@ declare(strict_types=1);
namespace ZM\Command\Server;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'server:status', description: '查看服务器状态')]
class ServerStatusCommand extends ServerCommand
{
protected static $defaultName = 'server:status';
protected function configure()
{
$this->setDescription('查看框架的运行状态');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
parent::execute($input, $output);

View File

@@ -5,19 +5,18 @@ declare(strict_types=1);
namespace ZM\Command\Server;
use Swoole\Process;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use ZM\Process\ProcessStateManager;
use ZM\Store\FileSystem;
#[AsCommand(name: 'server:stop', description: '停止服务器')]
class ServerStopCommand extends ServerCommand
{
protected static $defaultName = 'server:stop';
protected function configure()
{
$this->setDescription('停止运行的框架');
$this->setDefinition([
new InputOption('force', 'f', InputOption::VALUE_NONE, '强制停止'),
]);