mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-23 00:25:35 +08:00
update to v2.4.0 (build 400)
add systemd:generate command add check:config command init command add `--force|-F` option add MessageUtil function `addShortCommand()` clear debug message
This commit is contained in:
@@ -9,7 +9,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class CheckConfigCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'check-config';
|
||||
protected static $defaultName = 'check:config';
|
||||
|
||||
private $need_update = false;
|
||||
|
||||
@@ -17,14 +17,13 @@ class CheckConfigCommand extends Command
|
||||
$this->setDescription("检查配置文件是否和框架当前版本有更新");
|
||||
}
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
if (LOAD_MODE !== 1) {
|
||||
$output->writeln("<error>仅限在Composer依赖模式中使用此命令!");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
$current_cfg = WORKING_DIR . "/config/";
|
||||
$remote_cfg = include_once $current_cfg . "/vendor/zhamao/framework/config/global.php";
|
||||
$current_cfg = getcwd() . "/config/";
|
||||
$remote_cfg = include_once WORKING_DIR . "/config/global.php";
|
||||
if (file_exists($current_cfg . "global.php")) {
|
||||
$this->check($remote_cfg, "global.php", $output);
|
||||
}
|
||||
@@ -39,17 +38,23 @@ class CheckConfigCommand extends Command
|
||||
}
|
||||
if ($this->need_update === true) {
|
||||
$output->writeln("<comment>有配置文件需要更新,详情见文档 https://framework.zhamao.xin/update/config.md</comment>");
|
||||
} else {
|
||||
$output->writeln("<info>配置文件暂无更新!</info>");
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpIncludeInspection
|
||||
*/
|
||||
private function check($remote, $local, OutputInterface $out) {
|
||||
$local_file = include_once WORKING_DIR . "/config/".$local;
|
||||
$local_file = include_once getcwd() . "/config/".$local;
|
||||
foreach($remote as $k => $v) {
|
||||
$out->writeln("<comment>正在检查".$k."</comment>");
|
||||
if (!isset($local_file[$k])) {
|
||||
$out->writeln("<info>配置文件 ".$local . " 需要更新!</info>");
|
||||
$out->writeln("<error>配置文件 ".$local . " 需要更新!(缺少 `$k` 字段配置)</error>");
|
||||
$this->need_update = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ class InitCommand extends Command
|
||||
|
||||
protected function configure() {
|
||||
$this->setDescription("Initialize framework starter | 初始化框架运行的基础文件");
|
||||
$this->addOption("force", 'F', null, "强制重制,覆盖现有文件");
|
||||
$this->setHelp("此命令将会解压以下文件到项目的根目录:\n" . implode("\n", $this->getExtractFiles()));
|
||||
// ...
|
||||
}
|
||||
@@ -34,8 +35,9 @@ class InitCommand extends Command
|
||||
if (LOAD_MODE === 1) { // 从composer依赖而来的项目模式,最基本的需要初始化的模式
|
||||
$output->writeln("<comment>Initializing files</comment>");
|
||||
$base_path = LOAD_MODE_COMPOSER_PATH;
|
||||
$args = $input->getArgument("force");
|
||||
foreach ($this->extract_files as $file) {
|
||||
if (!file_exists($base_path . $file)) {
|
||||
if (!file_exists($base_path . $file) || $args) {
|
||||
$info = pathinfo($file);
|
||||
@mkdir($base_path . $info["dirname"], 0777, true);
|
||||
echo "Copying " . $file . PHP_EOL;
|
||||
@@ -67,8 +69,8 @@ class InitCommand extends Command
|
||||
}
|
||||
}
|
||||
file_put_contents($base_path . "/composer.json", json_encode($composer, 64 | 128 | 256));
|
||||
$output->writeln("<info>Executing composer update command</info>");
|
||||
exec("composer update");
|
||||
$output->writeln("<info>Executing composer command: `composer dump-autoload`</info>");
|
||||
exec("composer dump-autoload");
|
||||
echo PHP_EOL;
|
||||
} else {
|
||||
echo("Error occurred. Please check your updates.\n");
|
||||
|
||||
@@ -13,8 +13,30 @@ class SystemdCommand extends Command
|
||||
// the name of the command (the part after "bin/console")
|
||||
protected static $defaultName = 'systemd:generate';
|
||||
|
||||
protected function configure() {
|
||||
$this->setDescription("生成框架的 systemd 配置文件");
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
//TODO: 写一个生成systemd配置的功能,给2.0
|
||||
$path = $this->generate();
|
||||
$output->writeln("<info>成功生成 systemd 文件,位置:".$path."</info>");
|
||||
$output->writeln("<info>有关如何使用 systemd 配置文件,请访问 `https://github.com/zhamao-robot/zhamao-framework/issues/36`</info>");
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function generate() {
|
||||
$s = "[Unit]\nDescription=zhamao-framework Daemon\nAfter=rc-local.service\n\n[Service]\nType=simple";
|
||||
$s .= "\nUser=" . exec("whoami");
|
||||
$s .= "\nGroup=" . exec("groups | awk '{print $1}'");
|
||||
$s .= "\nWorkingDirectory=" . getcwd();
|
||||
if (LOAD_MODE == 1) {
|
||||
$s .= "\nExecStart=" . getcwd() . "/vendor/bin/start server";
|
||||
} else {
|
||||
$s .= "\nExecStart=" . getcwd() . "/bin/start server";
|
||||
}
|
||||
$s .= "\nRestart=always\n\n[Install]\nWantedBy=multi-user.target\n";
|
||||
@mkdir(getcwd() . "/resources/");
|
||||
file_put_contents(getcwd() . "/resources/zhamao.service", $s);
|
||||
return getcwd() . "/resources/zhamao.service";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user