add repl command (#155)

This commit is contained in:
sunxyw
2022-08-27 00:53:45 +08:00
committed by GitHub
parent 7920711988
commit 87e71f1eb8
3 changed files with 43 additions and 0 deletions

View File

@@ -21,6 +21,7 @@
"koriym/attributes": "^1.0",
"onebot/libonebot": "dev-develop",
"psr/container": "^2.0",
"psy/psysh": "^0.11.8",
"symfony/console": "^6.0 || ^5.0 || ^4.0",
"symfony/polyfill-ctype": "^1.19",
"symfony/polyfill-mbstring": "^1.19",

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace ZM\Command;
use Psy\Configuration;
use Psy\Shell;
use Psy\VersionUpdater\Checker;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use ZM\Framework;
class ReplCommand extends Command
{
protected static $defaultName = 'repl';
protected static $defaultDescription = '交互式控制台';
public function execute(InputInterface $input, OutputInterface $output): int
{
$config = Configuration::fromInput($input);
$config->setUpdateCheck(Checker::NEVER);
$config->setStartupMessage('你可以使用 "help" 来查看帮助');
$shell = new Shell($config);
$shell->addCommands([]); // TODO: add some great commands
try {
$output->writeln(sprintf('<fg=blue>Zhamao Repl on Zhamao Framework %s</>', Framework::VERSION));
$shell->run();
} catch (\Throwable $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
return Command::FAILURE;
}
return Command::SUCCESS;
}
}

View File

@@ -14,6 +14,7 @@ use ZM\Command\BuildCommand;
use ZM\Command\CheckConfigCommand;
use ZM\Command\Generate\SystemdGenerateCommand;
use ZM\Command\InitCommand;
use ZM\Command\ReplCommand;
use ZM\Command\Server\ServerReloadCommand;
use ZM\Command\Server\ServerStartCommand;
use ZM\Command\Server\ServerStatusCommand;
@@ -45,6 +46,7 @@ final class ConsoleApplication extends Application
$this->add(new ServerStartCommand()); // 运行主服务的指令控制器
$this->add(new SystemdGenerateCommand()); // 生成systemd文件
$this->add(new BotCraftCommand()); // 用于从命令行创建插件
$this->add(new ReplCommand()); // 交互式控制台
if (LOAD_MODE === 1) { // 如果是 Composer 模式加载的,那么可以输入 check:config 命令,检查配置文件是否需要更新
$this->add(new CheckConfigCommand());
}