Skip to main content

j_cli/command/
mod.rs

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