refactor: restructure project to modern Python layout, separate src, tests, docs, examples
This commit is contained in:
109
src/config_man/cli/main.py
Normal file
109
src/config_man/cli/main.py
Normal file
@@ -0,0 +1,109 @@
|
||||
import click
|
||||
import os
|
||||
from ..core.view_command import ViewCommand
|
||||
from ..utils.mock_rclone import patch_rclone
|
||||
|
||||
|
||||
@click.group()
|
||||
@click.version_option(version="0.1.0")
|
||||
def cli():
|
||||
"""Config-Man CLI 工具
|
||||
|
||||
用于管理存储在对象存储中的加密静态资源配置文件。
|
||||
支持多版本管理,通过Cloudflare CDN进行分发。
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.option('--version', required=True, help='版本号,格式为 0.29, 0.30, 0.31 等')
|
||||
@click.option('--json', 'json_format', is_flag=True, help='以JSON格式输出')
|
||||
@click.option('--storage-path', default='ab', help='对象存储路径前缀')
|
||||
@click.option('--cdn-url', default='', help='CDN基础URL')
|
||||
@click.option('--mock', is_flag=True, help='使用模拟环境进行测试')
|
||||
def view(version, json_format, storage_path, cdn_url, mock):
|
||||
"""查看配置文件
|
||||
|
||||
对比显示对象存储和CDN中的配置内容,支持Android和iOS平台。
|
||||
|
||||
示例:
|
||||
config-man view --version 0.30
|
||||
config-man view --version 0.30 --json
|
||||
config-man view --version 0.30 --mock
|
||||
"""
|
||||
try:
|
||||
# 如果使用模拟环境,启用rclone模拟
|
||||
if mock:
|
||||
patch_rclone()
|
||||
click.echo("使用模拟环境进行测试...")
|
||||
else:
|
||||
# 检查rclone是否可用
|
||||
if not _check_rclone():
|
||||
click.echo("错误: rclone 未安装或不可用。请先安装 rclone。")
|
||||
return 1
|
||||
|
||||
# 创建查看命令处理器
|
||||
view_cmd = ViewCommand(storage_path, cdn_url)
|
||||
|
||||
# 执行查看命令
|
||||
success = view_cmd.execute(version, json_format)
|
||||
|
||||
return 0 if success else 1
|
||||
|
||||
except Exception as e:
|
||||
click.echo(f"错误: {str(e)}")
|
||||
return 1
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.option('--platform', required=True, type=click.Choice(['android', 'ios']),
|
||||
help='平台类型')
|
||||
@click.option('--target-version', required=True, help='目标版本号')
|
||||
@click.option('--update-version', required=True, help='更新版本号')
|
||||
def suggest_update(platform, target_version, update_version):
|
||||
"""建议更新
|
||||
|
||||
在目标版本的配置文件中添加 Ver_New 属性,提示用户有新版本可用。
|
||||
|
||||
示例:
|
||||
config-man suggest-update --platform android --target-version 0.29 --update-version 0.30
|
||||
"""
|
||||
click.echo("建议更新功能尚未实现")
|
||||
return 1
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.option('--platform', required=True, type=click.Choice(['android', 'ios']),
|
||||
help='平台类型')
|
||||
@click.option('--target-version', required=True, help='目标版本号')
|
||||
@click.option('--update-version', required=True, help='更新版本号')
|
||||
def force_update(platform, target_version, update_version):
|
||||
"""强制更新
|
||||
|
||||
直接更新目标版本的 Ver 属性,强制用户升级到新版本。
|
||||
|
||||
示例:
|
||||
config-man force-update --platform ios --target-version 0.29 --update-version 0.30
|
||||
"""
|
||||
click.echo("强制更新功能尚未实现")
|
||||
return 1
|
||||
|
||||
|
||||
def _check_rclone():
|
||||
"""检查rclone是否可用"""
|
||||
import subprocess
|
||||
try:
|
||||
result = subprocess.run(['rclone', 'version'],
|
||||
capture_output=True, text=True, timeout=5)
|
||||
return result.returncode == 0
|
||||
except (subprocess.TimeoutExpired, FileNotFoundError):
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
cli()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user