Skip to main content

j_cli/command/
mod.rs

1pub mod alias;
2pub mod category;
3pub mod list;
4pub mod open;
5pub mod report;
6pub mod script;
7pub mod system;
8pub mod time;
9
10use crate::cli::SubCmd;
11use crate::config::YamlConfig;
12use crate::constants;
13
14/// 所有内置命令的关键字列表(用于判断别名冲突)
15/// 统一从 constants::cmd 模块获取,避免多处重复定义
16pub fn all_command_keywords() -> Vec<&'static str> {
17    constants::cmd::all_keywords()
18}
19
20/// 命令分发执行
21pub fn dispatch(subcmd: SubCmd, config: &mut YamlConfig) {
22    match subcmd {
23        // 别名管理
24        SubCmd::Set { alias, path } => alias::handle_set(&alias, &path, config),
25        SubCmd::Remove { alias } => alias::handle_remove(&alias, config),
26        SubCmd::Rename { alias, new_alias } => alias::handle_rename(&alias, &new_alias, config),
27        SubCmd::Modify { alias, path } => alias::handle_modify(&alias, &path, config),
28
29        // 分类标记
30        SubCmd::Note { alias, category } => category::handle_note(&alias, &category, config),
31        SubCmd::Denote { alias, category } => category::handle_denote(&alias, &category, config),
32
33        // 列表 & 查找
34        SubCmd::List { part } => list::handle_list(part.as_deref(), config),
35        SubCmd::Contain { alias, containers } => system::handle_contain(&alias, containers.as_deref(), config),
36
37        // 日报系统
38        SubCmd::Report { content } => report::handle_report("report", &content, config),
39        SubCmd::Reportctl { action, arg } => {
40            let mut args = vec![action];
41            if let Some(a) = arg {
42                args.push(a);
43            }
44            report::handle_report("reportctl", &args, config);
45        }
46        SubCmd::Check { line_count } => report::handle_check(line_count.as_deref(), config),
47        SubCmd::Search { line_count, target, fuzzy } => {
48            report::handle_search(&line_count, &target, fuzzy.as_deref(), config);
49        }
50
51        // 脚本
52        SubCmd::Concat { name, content } => script::handle_concat(&name, &content, config),
53
54        // 倒计时
55        SubCmd::Time { function, arg } => time::handle_time(&function, &arg),
56
57        // 系统设置
58        SubCmd::Log { key, value } => system::handle_log(&key, &value, config),
59        SubCmd::Change { part, field, value } => system::handle_change(&part, &field, &value, config),
60        SubCmd::Clear => system::handle_clear(),
61
62        // 系统信息
63        SubCmd::Version => system::handle_version(config),
64        SubCmd::Help => system::handle_help(),
65        SubCmd::Exit => system::handle_exit(),
66        SubCmd::Completion { shell } => system::handle_completion(shell.as_deref(), config),
67    }
68}