Skip to main content

nuwax_cli/
project_info.rs

1/// Nuwax Cli  项目信息模块
2///
3/// 由于 nuwax-cli 是面向用户的主程序,项目元数据统一在这里定义
4/// client-core 作为内部库,只提供技术性常量
5///
6/// 项目元数据(自动从 nuwax-cli 的 Cargo.toml 同步)
7pub mod metadata {
8    /// 项目名称(自动从 Cargo.toml 同步)
9    pub const PROJECT_NAME: &str = env!("CARGO_PKG_NAME");
10
11    /// 项目描述(自动从 Cargo.toml 同步)
12    pub const PROJECT_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
13
14    /// 项目作者(自动从 Cargo.toml 同步)
15    pub const PROJECT_AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
16
17    /// 项目许可证(自动从 Cargo.toml 同步)
18    pub const PROJECT_LICENSE: &str = env!("CARGO_PKG_LICENSE");
19
20    /// 项目仓库地址(自动从 Cargo.toml 同步)
21    pub const PROJECT_REPOSITORY: &str = env!("CARGO_PKG_REPOSITORY");
22
23    /// 项目主页(自动从 Cargo.toml 同步)
24    pub const PROJECT_HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE");
25
26    /// 项目文档地址(自动从 Cargo.toml 同步)
27    pub const PROJECT_DOCUMENTATION: &str = env!("CARGO_PKG_HOMEPAGE");
28
29    /// 用户友好的显示名称(手动维护,用于 UI 显示)
30    pub mod display {
31        /// 用户友好的项目名称
32        pub const FRIENDLY_NAME: &str = "Nuwax Cli ent";
33
34        /// CLI 工具的完整名称
35        pub const CLI_FULL_NAME: &str = "Nuwax Cli ent CLI";
36
37        /// 项目详细描述(比 Cargo.toml 中的描述更详细)
38        pub const DESCRIPTION_LONG: &str = "An automated Docker service management and upgrade platform client, with centralized Docker Compose management, automatic backups, smart upgrades, and operations monitoring.";
39    }
40
41    /// 项目关键词
42    pub const PROJECT_KEYWORDS: &[&str] = &[
43        "docker",
44        "service-management",
45        "automation",
46        "deployment",
47        "backup",
48        "upgrade",
49        "monitoring",
50    ];
51
52    /// 项目分类
53    pub const PROJECT_CATEGORIES: &[&str] = &[
54        "command-line-utilities",
55        "development-tools",
56        "containerization",
57    ];
58}
59
60/// 版本信息
61pub mod version_info {
62    /// CLI 版本(自动从 Cargo.toml 同步)
63    pub const CLI_VERSION: &str = env!("CARGO_PKG_VERSION");
64
65    /// 核心库版本(从 client-core 获取)
66    pub const CORE_VERSION: &str = client_core::constants::version::version_info::CORE_VERSION;
67
68    /// Docker 服务版本(从 client-core 获取)
69    pub const DOCKER_SERVICE_VERSION: &str =
70        client_core::constants::version::version_info::DEFAULT_DOCKER_SERVICE_VERSION;
71}
72
73/// 项目完整信息结构
74#[derive(Debug, Clone)]
75pub struct ProjectInfo {
76    pub name: &'static str,
77    pub full_name: &'static str,
78    pub description: &'static str,
79    pub description_long: &'static str,
80    pub version: &'static str,
81    pub authors: &'static str,
82    pub license: &'static str,
83    pub repository: &'static str,
84    pub homepage: &'static str,
85    pub documentation: &'static str,
86    pub keywords: &'static [&'static str],
87    pub categories: &'static [&'static str],
88}
89
90/// 获取完整的项目信息
91pub fn get_project_info() -> ProjectInfo {
92    ProjectInfo {
93        name: metadata::PROJECT_NAME,
94        full_name: metadata::display::CLI_FULL_NAME,
95        description: metadata::PROJECT_DESCRIPTION,
96        description_long: metadata::display::DESCRIPTION_LONG,
97        version: version_info::CLI_VERSION,
98        authors: metadata::PROJECT_AUTHORS,
99        license: metadata::PROJECT_LICENSE,
100        repository: metadata::PROJECT_REPOSITORY,
101        homepage: metadata::PROJECT_HOMEPAGE,
102        documentation: metadata::PROJECT_DOCUMENTATION,
103        keywords: metadata::PROJECT_KEYWORDS,
104        categories: metadata::PROJECT_CATEGORIES,
105    }
106}
107
108/// 获取版本信息字符串
109pub fn get_version_string() -> String {
110    format!(
111        "{} v{}",
112        metadata::display::FRIENDLY_NAME,
113        version_info::CLI_VERSION
114    )
115}
116
117/// 获取完整的版本信息字符串(包含描述)
118pub fn get_full_version_string() -> String {
119    format!(
120        "{} v{}\n{}",
121        metadata::display::CLI_FULL_NAME,
122        version_info::CLI_VERSION,
123        metadata::PROJECT_DESCRIPTION
124    )
125}
126
127/// 获取作者和许可证信息
128pub fn get_copyright_info() -> String {
129    format!(
130        "© {} - Licensed under {}",
131        metadata::PROJECT_AUTHORS,
132        metadata::PROJECT_LICENSE
133    )
134}
135
136/// 获取系统要求信息
137pub fn get_system_requirements() -> SystemRequirements {
138    use client_core::constants::version::version_info as core_version;
139
140    SystemRequirements {
141        min_docker_version: core_version::MIN_DOCKER_VERSION,
142        min_compose_version: core_version::MIN_COMPOSE_VERSION,
143        api_version: core_version::API_VERSION,
144        config_format_version: core_version::CONFIG_FORMAT_VERSION,
145        database_schema_version: core_version::DATABASE_SCHEMA_VERSION,
146    }
147}
148
149/// 系统要求信息结构
150#[derive(Debug, Clone)]
151pub struct SystemRequirements {
152    pub min_docker_version: &'static str,
153    pub min_compose_version: &'static str,
154    pub api_version: &'static str,
155    pub config_format_version: &'static str,
156    pub database_schema_version: &'static str,
157}