- 新增 ForceUpdateCommand 类实现强制更新功能 - 添加 force-update CLI 命令支持 - 实现参数验证、配置对比、CDN缓存刷新 - 添加完整的测试用例和使用示例 - 更新文档和进度跟踪 - 支持模拟环境测试 - 添加警告提示和错误处理 主要文件: - src/config_man/core/force_update_command.py (新增) - src/config_man/cli/main.py (更新) - examples/test_force_update.py (新增) - examples/force_update_usage.py (新增) - docs/progress-tracker.md (更新)
116 lines
4.4 KiB
Python
116 lines
4.4 KiB
Python
from typing import Dict, List
|
|
from rich.console import Console
|
|
from rich.table import Table
|
|
from rich.panel import Panel
|
|
from rich.text import Text
|
|
import json
|
|
from ..utils.config import config
|
|
|
|
|
|
class DisplayManager:
|
|
"""显示管理器"""
|
|
|
|
def __init__(self):
|
|
self.console = Console()
|
|
self.display_config = config.get_display_config()
|
|
|
|
def display_config_comparison(self, version: str, platform: str,
|
|
storage_config: Dict, cdn_config: Dict,
|
|
differences: Dict):
|
|
"""显示配置对比结果"""
|
|
|
|
# 创建标题
|
|
title = f"版本: {version} | 平台: {platform.title()}"
|
|
self.console.print(f"\n[bold blue]{title}[/bold blue]")
|
|
|
|
# 创建表格
|
|
table = Table(show_header=True, header_style="bold magenta")
|
|
table.add_column("配置项", style="cyan", width=20)
|
|
table.add_column("对象存储内容", style="green", width=30)
|
|
table.add_column("CDN内容", style="yellow", width=30)
|
|
table.add_column("状态", style="red", width=10)
|
|
|
|
# 添加数据行
|
|
truncate_length = self.display_config.get('truncate_length', 25)
|
|
for key, data in differences.items():
|
|
storage_value = str(data["storage"])
|
|
cdn_value = str(data["cdn"])
|
|
status = "❌ 不同" if data["different"] else "✅ 一致"
|
|
|
|
# 截断过长的值
|
|
if len(storage_value) > truncate_length:
|
|
storage_value = storage_value[:truncate_length-3] + "..."
|
|
if len(cdn_value) > truncate_length:
|
|
cdn_value = cdn_value[:truncate_length-3] + "..."
|
|
|
|
table.add_row(key, storage_value, cdn_value, status)
|
|
|
|
self.console.print(table)
|
|
|
|
def display_json_format(self, version: str, platform: str,
|
|
storage_config: Dict, cdn_config: Dict):
|
|
"""以JSON格式显示配置"""
|
|
|
|
title = f"版本: {version} | 平台: {platform.title()}"
|
|
self.console.print(f"\n[bold blue]{title}[/bold blue]")
|
|
|
|
# 创建对比JSON
|
|
comparison = {
|
|
"version": version,
|
|
"platform": platform,
|
|
"storage_config": storage_config,
|
|
"cdn_config": cdn_config
|
|
}
|
|
|
|
# 格式化JSON输出
|
|
json_str = json.dumps(comparison, indent=2, ensure_ascii=False)
|
|
|
|
# 使用面板显示
|
|
panel = Panel(
|
|
json_str,
|
|
title="JSON格式",
|
|
border_style="blue"
|
|
)
|
|
self.console.print(panel)
|
|
|
|
def display_summary(self, version: str, results: Dict):
|
|
"""显示总结信息"""
|
|
|
|
self.console.print(f"\n[bold green]配置查看总结[/bold green]")
|
|
self.console.print(f"版本: {version}")
|
|
|
|
for platform in ["android", "ios"]:
|
|
if platform in results:
|
|
result = results[platform]
|
|
if result["success"]:
|
|
storage_keys = len(result["storage_config"])
|
|
cdn_keys = len(result["cdn_config"])
|
|
differences = sum(1 for data in result["differences"].values()
|
|
if data["different"])
|
|
|
|
status = "✅ 正常" if differences == 0 else f"⚠️ {differences} 项不同"
|
|
|
|
self.console.print(
|
|
f" {platform.title()}: {status} "
|
|
f"(存储: {storage_keys}项, CDN: {cdn_keys}项)"
|
|
)
|
|
else:
|
|
self.console.print(f" {platform.title()}: ❌ 失败")
|
|
else:
|
|
self.console.print(f" {platform.title()}: ⚠️ 未检查")
|
|
|
|
def display_error(self, message: str):
|
|
"""显示错误信息"""
|
|
self.console.print(f"[bold red]错误: {message}[/bold red]")
|
|
|
|
def display_warning(self, message: str):
|
|
"""显示警告信息"""
|
|
self.console.print(f"[bold yellow]警告: {message}[/bold yellow]")
|
|
|
|
def display_info(self, message: str):
|
|
"""显示信息"""
|
|
self.console.print(f"[bold blue]信息: {message}[/bold blue]")
|
|
|
|
def display_success(self, message: str):
|
|
"""显示成功信息"""
|
|
self.console.print(f"[bold green]✅ 成功: {message}[/bold green]") |