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