Files
ulthon_admin/extend/base/common/command/admin/UpdateBase.php

58 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace base\common\command\admin;
use app\admin\service\AdminUpdateService;
use app\common\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
class UpdateBase extends Command
{
public const REPO = null;
protected function configure()
{
parent::configure();
// 指令配置
$this->setName('admin:update')
->addOption('reinstall', null, Option::VALUE_NONE, '重装版本')
->addOption('update-ulthon', null, Option::VALUE_NONE, '更新 ulthon_admin')
->addOption('update-master', null, Option::VALUE_NONE, '更新 ulthon_admin 的 master 分支')
->addOption('dry-run', null, Option::VALUE_NONE, '预览模式,只输出变更不执行')
->addOption('optional-conflict', null, Option::VALUE_OPTIONAL, '可选文件冲突处理策略: skip|overwrite|ask')
->addOption('force-conflict', null, Option::VALUE_OPTIONAL, '强制文件冲突处理策略: overwrite|skip|ask')
->addOption('show', null, Option::VALUE_OPTIONAL, '变更输出范围: all|conflict')
->addOption('keep-repo', null, Option::VALUE_NONE, '预览模式下保留上游克隆目录,便于手动对比跳过的文件')
->setDescription('更新系统代码');
}
protected function execute(Input $input, Output $output)
{
// 指令输出
$output->writeln('admin:update');
$repo = static::REPO;
if ((bool)$input->getOption('update-ulthon')) {
$repo = 'ulthon_admin';
}
$update_service = new AdminUpdateService($repo);
$update_service->input = $input;
$update_service->output = $output;
$update_service->dryRun = (bool)$input->getOption('dry-run');
$update_service->optionalConflict = $input->getOption('optional-conflict') ?: null;
$update_service->forceConflict = $input->getOption('force-conflict') ?: null;
$update_service->showScope = $input->getOption('show') ?: null;
$update_service->keepRepo = (bool)$input->getOption('keep-repo');
$update_service->update();
}
}