diff --git a/composer.json b/composer.json index 0d8a7207..ca0c8537 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/ZM/Command/ReplCommand.php b/src/ZM/Command/ReplCommand.php new file mode 100644 index 00000000..5ea101f2 --- /dev/null +++ b/src/ZM/Command/ReplCommand.php @@ -0,0 +1,40 @@ +setUpdateCheck(Checker::NEVER); + $config->setStartupMessage('你可以使用 "help" 来查看帮助'); + + $shell = new Shell($config); + $shell->addCommands([]); // TODO: add some great commands + + try { + $output->writeln(sprintf('Zhamao Repl on Zhamao Framework %s', Framework::VERSION)); + $shell->run(); + } catch (\Throwable $e) { + $output->writeln(sprintf('%s', $e->getMessage())); + return Command::FAILURE; + } + + return Command::SUCCESS; + } +} diff --git a/src/ZM/ConsoleApplication.php b/src/ZM/ConsoleApplication.php index f2a7a760..f13a12de 100644 --- a/src/ZM/ConsoleApplication.php +++ b/src/ZM/ConsoleApplication.php @@ -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()); }