Skip to main content

j_cli/
constants.rs

1// 项目全局常量定义
2// 所有魔法字符串和可复用常量统一在此维护
3
4// ========== 版本信息 ==========
5
6/// 内核版本号(自动从 Cargo.toml 读取,编译时确定)
7pub const VERSION: &str = env!("CARGO_PKG_VERSION");
8
9/// 项目名称
10pub const APP_NAME: &str = "work-copilot";
11
12/// 作者
13pub const AUTHOR: &str = "lingojack";
14
15/// 邮箱
16pub const EMAIL: &str = "lingojack@qq.com";
17
18/// GitHub 仓库 URL
19pub const GITHUB_REPO: &str = "LingoJack/j";
20
21/// GitHub Releases API URL
22pub const GITHUB_RELEASES_API: &str = "https://api.github.com/repos/LingoJack/j/releases/latest";
23
24/// 版本检查缓存文件名
25pub const VERSION_CHECK_CACHE_FILE: &str = "version_check.json";
26
27/// 版本检查间隔(秒),默认 24 小时
28pub const VERSION_CHECK_INTERVAL_SECS: u64 = 24 * 60 * 60;
29
30// ========== Section 名称 ==========
31
32/// 配置文件中的 section 名称常量
33pub mod section {
34    pub const PATH: &str = "path";
35    pub const INNER_URL: &str = "inner_url";
36    pub const OUTER_URL: &str = "outer_url";
37    pub const EDITOR: &str = "editor";
38    pub const BROWSER: &str = "browser";
39    pub const VPN: &str = "vpn";
40    pub const SCRIPT: &str = "script";
41    pub const VERSION: &str = "version";
42    pub const SETTING: &str = "setting";
43    pub const LOG: &str = "log";
44    pub const REPORT: &str = "report";
45}
46
47/// 所有 section 名称列表(有序)
48pub const ALL_SECTIONS: &[&str] = &[
49    section::PATH,
50    section::INNER_URL,
51    section::OUTER_URL,
52    section::EDITOR,
53    section::BROWSER,
54    section::VPN,
55    section::SCRIPT,
56    section::VERSION,
57    section::SETTING,
58    section::LOG,
59    section::REPORT,
60];
61
62/// 默认展示的 section(ls 命令无参数时使用)
63pub const DEFAULT_DISPLAY_SECTIONS: &[&str] = &[
64    section::PATH,
65    section::INNER_URL,
66    section::OUTER_URL,
67    section::EDITOR,
68    section::BROWSER,
69    section::VPN,
70    section::SCRIPT,
71];
72
73/// contain 命令默认搜索的 section
74pub const CONTAIN_SEARCH_SECTIONS: &[&str] = &[
75    section::PATH,
76    section::SCRIPT,
77    section::BROWSER,
78    section::EDITOR,
79    section::VPN,
80    section::INNER_URL,
81    section::OUTER_URL,
82];
83
84// ========== 分类标记 ==========
85
86/// 可标记的分类列表(note/denote 命令使用)
87pub const NOTE_CATEGORIES: &[&str] = &[
88    section::BROWSER,
89    section::EDITOR,
90    section::VPN,
91    section::OUTER_URL,
92    section::SCRIPT,
93];
94
95// ========== 别名查找 section ==========
96
97/// 用于查找别名路径的 section 列表(按优先级排列)
98pub const ALIAS_PATH_SECTIONS: &[&str] = &[
99    section::PATH,
100    section::INNER_URL,
101    section::OUTER_URL,
102];
103
104/// 用于判断别名是否存在的 section 列表
105pub const ALIAS_EXISTS_SECTIONS: &[&str] = &[
106    section::PATH,
107    section::INNER_URL,
108    section::OUTER_URL,
109    section::SCRIPT,
110    section::BROWSER,
111    section::EDITOR,
112    section::VPN,
113];
114
115/// modify 命令需要检查并更新的 section 列表
116pub const MODIFY_SECTIONS: &[&str] = &[
117    section::PATH,
118    section::INNER_URL,
119    section::OUTER_URL,
120    section::EDITOR,
121    section::BROWSER,
122    section::VPN,
123];
124
125/// remove 时需要同步清理的 category section
126pub const REMOVE_CLEANUP_SECTIONS: &[&str] = &[
127    section::EDITOR,
128    section::VPN,
129    section::BROWSER,
130    section::SCRIPT,
131];
132
133/// rename 时需要同步重命名的 category section
134pub const RENAME_SYNC_SECTIONS: &[&str] = &[
135    section::BROWSER,
136    section::EDITOR,
137    section::VPN,
138    section::SCRIPT,
139];
140
141// ========== 配置 key ==========
142
143/// 配置 key 名称常量
144pub mod config_key {
145    pub const MODE: &str = "mode";
146    pub const VERBOSE: &str = "verbose";
147    pub const CONCISE: &str = "concise";
148    pub const SEARCH_ENGINE: &str = "search-engine";
149    pub const WEEK_REPORT: &str = "week_report";
150    pub const WEEK_NUM: &str = "week_num";
151    pub const LAST_DAY: &str = "last_day";
152    pub const GIT_REPO: &str = "git_repo";
153}
154
155// ========== 搜索引擎 ==========
156
157/// 默认搜索引擎
158pub const DEFAULT_SEARCH_ENGINE: &str = "bing";
159
160/// 搜索引擎 URL 模板
161pub mod search_engine {
162    pub const GOOGLE: &str = "https://www.google.com/search?q={}";
163    pub const BING: &str = "https://www.bing.com/search?q={}";
164    pub const BAIDU: &str = "https://www.baidu.com/s?wd={}";
165}
166
167// ========== 日报相关 ==========
168
169/// 日报日期格式
170pub const REPORT_DATE_FORMAT: &str = "%Y.%m.%d";
171
172/// 日报简短日期格式
173pub const REPORT_SIMPLE_DATE_FORMAT: &str = "%Y/%m/%d";
174
175/// check 命令默认行数
176pub const DEFAULT_CHECK_LINES: usize = 5;
177
178// ========== 命令名常量 ==========
179
180/// 所有内置命令的名称和别名,统一在此维护
181/// interactive.rs 的补全规则 / parse_interactive_command 和 command/mod.rs 的 all_command_keywords 共同引用
182pub mod cmd {
183    // 别名管理
184    pub const SET: &[&str] = &["set", "s"];
185    pub const REMOVE: &[&str] = &["rm", "remove"];
186    pub const RENAME: &[&str] = &["rename", "rn"];
187    pub const MODIFY: &[&str] = &["mf", "modify"];
188
189    // 分类标记
190    pub const NOTE: &[&str] = &["note", "nt"];
191    pub const DENOTE: &[&str] = &["denote", "dnt"];
192
193    // 列表 & 查找
194    pub const LIST: &[&str] = &["ls", "list"];
195    pub const CONTAIN: &[&str] = &["contain", "find"];
196
197    // 日报系统
198    pub const REPORT: &[&str] = &["report", "r"];
199    pub const REPORTCTL: &[&str] = &["reportctl", "rctl"];
200    pub const CHECK: &[&str] = &["check", "c"];
201    pub const SEARCH: &[&str] = &["search", "select", "look", "sch"];
202
203    // 脚本
204    pub const CONCAT: &[&str] = &["concat"];
205
206    // 倒计时
207    pub const TIME: &[&str] = &["time"];
208
209    // 系统设置
210    pub const LOG: &[&str] = &["log"];
211    pub const CHANGE: &[&str] = &["change", "chg"];
212    pub const CLEAR: &[&str] = &["clear", "cls"];
213
214    // 系统信息
215    pub const VERSION: &[&str] = &["version", "v"];
216    pub const HELP: &[&str] = &["help", "h"];
217    pub const EXIT: &[&str] = &["exit", "q", "quit"];
218
219    // shell 补全
220    pub const COMPLETION: &[&str] = &["completion"];
221
222    // agent(预留)
223    pub const AGENT: &[&str] = &["agent"];
224    pub const SYSTEM: &[&str] = &["system", "ps"];
225
226    /// 获取所有内置命令关键字的扁平列表(用于判断别名冲突等)
227    pub fn all_keywords() -> Vec<&'static str> {
228        let groups: &[&[&str]] = &[
229            SET, REMOVE, RENAME, MODIFY,
230            NOTE, DENOTE,
231            LIST, CONTAIN,
232            REPORT, REPORTCTL, CHECK, SEARCH,
233            CONCAT, TIME,
234            LOG, CHANGE, CLEAR,
235            VERSION, HELP, EXIT,
236            COMPLETION,
237            AGENT, SYSTEM,
238        ];
239        groups.iter().flat_map(|g| g.iter().copied()).collect()
240    }
241}
242
243// ========== reportctl 子命令 ==========
244
245pub mod rmeta_action {
246    pub const NEW: &str = "new";
247    pub const SYNC: &str = "sync";
248    pub const PUSH: &str = "push";
249    pub const PULL: &str = "pull";
250    pub const SET_URL: &str = "set-url";
251    pub const OPEN: &str = "open";
252}
253
254// ========== time 子命令 ==========
255
256pub mod time_function {
257    pub const COUNTDOWN: &str = "countdown";
258}
259
260// ========== search 标记 ==========
261
262pub mod search_flag {
263    pub const FUZZY_SHORT: &str = "-f";
264    pub const FUZZY: &str = "-fuzzy";
265}
266
267// ========== ls 补全固定选项 ==========
268
269pub const LIST_ALL: &str = "all";
270
271// ========== 交互模式 ==========
272
273/// 欢迎语
274pub const WELCOME_MESSAGE: &str = "Welcome to use work copilot 🚀 ~";
275
276/// Shell 命令前缀字符
277pub const SHELL_PREFIX: char = '!';
278
279/// 交互模式提示符
280pub const INTERACTIVE_PROMPT: &str = "copilot >";
281
282/// 历史记录文件名
283pub const HISTORY_FILE: &str = "history.txt";
284
285/// 配置文件名
286pub const CONFIG_FILE: &str = "config.yaml";
287
288/// 脚本目录名
289pub const SCRIPTS_DIR: &str = "scripts";
290
291/// 日报目录名
292pub const REPORT_DIR: &str = "report";
293
294/// 日报默认文件名
295pub const REPORT_DEFAULT_FILE: &str = "week_report.md";
296
297/// 数据根目录名
298pub const DATA_DIR: &str = ".jdata";
299
300/// 数据路径环境变量名
301pub const DATA_PATH_ENV: &str = "J_DATA_PATH";
302
303// ========== Shell 命令 ==========
304
305pub mod shell {
306    pub const BASH_PATH: &str = "/bin/bash";
307    pub const WINDOWS_CMD: &str = "cmd";
308    pub const WINDOWS_CMD_FLAG: &str = "/c";
309    pub const BASH_CMD_FLAG: &str = "-c";
310    pub const WINDOWS_OS: &str = "windows";
311    pub const MACOS_OS: &str = "macos";
312}