mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-25 17:45:34 +08:00
add repl command (#155)
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
"koriym/attributes": "^1.0",
|
"koriym/attributes": "^1.0",
|
||||||
"onebot/libonebot": "dev-develop",
|
"onebot/libonebot": "dev-develop",
|
||||||
"psr/container": "^2.0",
|
"psr/container": "^2.0",
|
||||||
|
"psy/psysh": "^0.11.8",
|
||||||
"symfony/console": "^6.0 || ^5.0 || ^4.0",
|
"symfony/console": "^6.0 || ^5.0 || ^4.0",
|
||||||
"symfony/polyfill-ctype": "^1.19",
|
"symfony/polyfill-ctype": "^1.19",
|
||||||
"symfony/polyfill-mbstring": "^1.19",
|
"symfony/polyfill-mbstring": "^1.19",
|
||||||
|
|||||||
40
src/ZM/Command/ReplCommand.php
Normal file
40
src/ZM/Command/ReplCommand.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ use ZM\Command\BuildCommand;
|
|||||||
use ZM\Command\CheckConfigCommand;
|
use ZM\Command\CheckConfigCommand;
|
||||||
use ZM\Command\Generate\SystemdGenerateCommand;
|
use ZM\Command\Generate\SystemdGenerateCommand;
|
||||||
use ZM\Command\InitCommand;
|
use ZM\Command\InitCommand;
|
||||||
|
use ZM\Command\ReplCommand;
|
||||||
use ZM\Command\Server\ServerReloadCommand;
|
use ZM\Command\Server\ServerReloadCommand;
|
||||||
use ZM\Command\Server\ServerStartCommand;
|
use ZM\Command\Server\ServerStartCommand;
|
||||||
use ZM\Command\Server\ServerStatusCommand;
|
use ZM\Command\Server\ServerStatusCommand;
|
||||||
@@ -45,6 +46,7 @@ final class ConsoleApplication extends Application
|
|||||||
$this->add(new ServerStartCommand()); // 运行主服务的指令控制器
|
$this->add(new ServerStartCommand()); // 运行主服务的指令控制器
|
||||||
$this->add(new SystemdGenerateCommand()); // 生成systemd文件
|
$this->add(new SystemdGenerateCommand()); // 生成systemd文件
|
||||||
$this->add(new BotCraftCommand()); // 用于从命令行创建插件
|
$this->add(new BotCraftCommand()); // 用于从命令行创建插件
|
||||||
|
$this->add(new ReplCommand()); // 交互式控制台
|
||||||
if (LOAD_MODE === 1) { // 如果是 Composer 模式加载的,那么可以输入 check:config 命令,检查配置文件是否需要更新
|
if (LOAD_MODE === 1) { // 如果是 Composer 模式加载的,那么可以输入 check:config 命令,检查配置文件是否需要更新
|
||||||
$this->add(new CheckConfigCommand());
|
$this->add(new CheckConfigCommand());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user