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