- 新增 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 (更新)
126 lines
3.6 KiB
Python
126 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
建议更新功能使用示例
|
|
|
|
这个脚本演示了如何使用 config-man 的建议更新功能。
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
# 添加项目根目录到Python路径
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
from src.config_man.core.suggest_update_command import SuggestUpdateCommand
|
|
from src.config_man.utils.mock_rclone import patch_rclone
|
|
|
|
|
|
def example_suggest_update():
|
|
"""建议更新功能示例"""
|
|
|
|
print("📋 建议更新功能使用示例")
|
|
print("=" * 50)
|
|
|
|
# 启用模拟环境
|
|
patch_rclone()
|
|
|
|
# 创建建议更新命令处理器
|
|
suggest_cmd = SuggestUpdateCommand("ab", "https://cdn.example.com")
|
|
|
|
# 示例1: Android平台建议更新
|
|
print("\n📱 示例1: Android平台建议更新")
|
|
print("目标版本: 0.29 -> 更新版本: 0.30")
|
|
|
|
success = suggest_cmd.execute("android", "0.29", "0.30")
|
|
|
|
if success:
|
|
print("✅ Android平台建议更新成功")
|
|
else:
|
|
print("❌ Android平台建议更新失败")
|
|
|
|
# 示例2: iOS平台建议更新
|
|
print("\n📱 示例2: iOS平台建议更新")
|
|
print("目标版本: 0.29 -> 更新版本: 0.30")
|
|
|
|
success = suggest_cmd.execute("ios", "0.29", "0.30")
|
|
|
|
if success:
|
|
print("✅ iOS平台建议更新成功")
|
|
else:
|
|
print("❌ iOS平台建议更新失败")
|
|
|
|
# 示例3: 错误处理
|
|
print("\n🚫 示例3: 错误处理")
|
|
|
|
# 测试无效平台
|
|
print("测试无效平台...")
|
|
success = suggest_cmd.execute("invalid", "0.29", "0.30")
|
|
if not success:
|
|
print("✅ 正确处理了无效平台错误")
|
|
|
|
# 测试相同版本
|
|
print("测试相同版本...")
|
|
success = suggest_cmd.execute("android", "0.29", "0.29")
|
|
if not success:
|
|
print("✅ 正确处理了相同版本错误")
|
|
|
|
# 测试无效版本格式
|
|
print("测试无效版本格式...")
|
|
success = suggest_cmd.execute("android", "invalid", "0.30")
|
|
if not success:
|
|
print("✅ 正确处理了无效版本格式错误")
|
|
|
|
print("\n🎉 建议更新功能示例完成!")
|
|
|
|
|
|
def show_cli_usage():
|
|
"""显示CLI使用方式"""
|
|
|
|
print("\n🔧 CLI使用方式")
|
|
print("=" * 50)
|
|
|
|
print("1. 基本用法:")
|
|
print(" config-man suggest-update --platform android --target-version 0.29 --update-version 0.30")
|
|
|
|
print("\n2. 指定存储路径和CDN URL:")
|
|
print(" config-man suggest-update --platform ios --target-version 0.29 --update-version 0.30 --storage-path custom/path --cdn-url https://custom.cdn.com")
|
|
|
|
print("\n3. 使用模拟环境测试:")
|
|
print(" config-man suggest-update --platform android --target-version 0.29 --update-version 0.30 --mock")
|
|
|
|
print("\n4. 查看帮助信息:")
|
|
print(" config-man suggest-update --help")
|
|
|
|
|
|
def show_config_changes():
|
|
"""显示配置变更示例"""
|
|
|
|
print("\n📝 配置变更示例")
|
|
print("=" * 50)
|
|
|
|
print("修改前:")
|
|
print("""{
|
|
"Ver": "0.29.1abc123",
|
|
"EventApiURL": "https://n3backend.azurewebsites.net/",
|
|
"PlayFabTitle": "B066F"
|
|
}""")
|
|
|
|
print("\n修改后:")
|
|
print("""{
|
|
"Ver": "0.29.1abc123",
|
|
"Ver_New": "0.30.1def456",
|
|
"EventApiURL": "https://n3backend.azurewebsites.net/",
|
|
"PlayFabTitle": "B066F"
|
|
}""")
|
|
|
|
print("\n说明:")
|
|
print("- 在目标版本(0.29)的配置中添加了 Ver_New 属性")
|
|
print("- Ver_New 的值来自更新版本(0.30)的 Ver 属性")
|
|
print("- 这样客户端可以检测到有新版本可用")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
example_suggest_update()
|
|
show_cli_usage()
|
|
show_config_changes()
|