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