Skip to main content

j_cli/
cli.rs

1use crate::constants;
2use clap::{Parser, Subcommand};
3
4/// work-copilot (j) - 快捷命令行工具 🚀
5#[derive(Parser, Debug)]
6#[command(name = "j", version = constants::VERSION, about = "快捷命令行工具", long_about = None)]
7#[command(disable_help_subcommand = true)]
8pub struct Cli {
9    #[command(subcommand)]
10    pub command: Option<SubCmd>,
11
12    /// 当没有匹配到子命令时,收集所有剩余参数(用于别名打开)
13    #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
14    pub args: Vec<String>,
15}
16
17#[derive(Subcommand, Debug)]
18pub enum SubCmd {
19    // ========== 别名管理 ==========
20    /// 设置别名(路径/URL)
21    #[command(alias = "s")]
22    Set {
23        /// 别名
24        alias: String,
25        /// 路径或 URL(支持空格,多个参数会拼接)
26        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
27        path: Vec<String>,
28    },
29
30    /// 删除别名
31    #[command(alias = "rm")]
32    Remove {
33        /// 要删除的别名
34        alias: String,
35    },
36
37    /// 重命名别名
38    #[command(alias = "rn")]
39    Rename {
40        /// 原别名
41        alias: String,
42        /// 新别名
43        new_alias: String,
44    },
45
46    /// 修改别名对应的路径
47    #[command(alias = "mf")]
48    Modify {
49        /// 别名
50        alias: String,
51        /// 新路径或 URL
52        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
53        path: Vec<String>,
54    },
55
56    // ========== 分类标记 ==========
57    /// 标记别名为指定分类(browser/editor/vpn/outer_url/script)
58    #[command(alias = "nt")]
59    Note {
60        /// 别名
61        alias: String,
62        /// 分类: browser, editor, vpn, outer_url, script
63        category: String,
64    },
65
66    /// 解除别名的分类标记
67    #[command(alias = "dnt")]
68    Denote {
69        /// 别名
70        alias: String,
71        /// 分类: browser, editor, vpn, outer_url, script
72        category: String,
73    },
74
75    // ========== 列表 ==========
76    /// 列出别名
77    #[command(alias = "ls")]
78    List {
79        /// 指定 section(可选,如 path/inner_url/all 等)
80        part: Option<String>,
81    },
82
83    /// 在指定分类中查找别名
84    #[command(alias = "find")]
85    Contain {
86        /// 要搜索的别名
87        alias: String,
88        /// 可选的分类列表(逗号分隔,如 path,browser,vpn)
89        containers: Option<String>,
90    },
91
92    // ========== 日报系统 ==========
93    /// 写入日报
94    #[command(aliases = ["r"])]
95    Report {
96        /// 日报内容(支持多个参数拼接)
97        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
98        content: Vec<String>,
99    },
100
101    /// 日报元数据操作(new/sync/push/pull)
102    #[command(name = "reportctl", alias = "rctl")]
103    Reportctl {
104        /// 操作: new / sync / push / pull
105        action: String,
106        /// 可选参数(new/sync 时为日期,push 时为 commit message)
107        arg: Option<String>,
108    },
109
110    /// 查看日报最近 N 行
111    #[command(alias = "c")]
112    Check {
113        /// 行数(默认 5)
114        line_count: Option<String>,
115    },
116
117    /// 在日报中搜索关键字
118    #[command(aliases = ["select", "look", "sch"])]
119    Search {
120        /// 行数或 "all"
121        line_count: String,
122        /// 搜索关键字
123        target: String,
124        /// 可选: -f 或 -fuzzy 启用模糊匹配
125        #[arg(allow_hyphen_values = true)]
126        fuzzy: Option<String>,
127    },
128
129    // ========== 待办备忘录 ==========
130    /// 待办备忘录(无参数进入 TUI 界面,有参数快速添加)
131    #[command(alias = "td")]
132    Todo {
133        /// 待办内容(支持多个参数拼接)
134        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
135        content: Vec<String>,
136    },
137
138    // ========== 脚本 ==========
139    /// 创建脚本
140    Concat {
141        /// 脚本名称
142        name: String,
143        /// 脚本内容(可选,不提供则打开 TUI 编辑器)
144        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
145        content: Vec<String>,
146    },
147
148    // ========== 计时器 ==========
149    /// 倒计时器
150    Time {
151        /// 功能名称(目前支持: countdown)
152        function: String,
153        /// 参数(时长,如 30s、5m、1h)
154        arg: String,
155    },
156
157    // ========== 系统设置 ==========
158    /// 日志模式设置
159    Log {
160        /// 设置项名称(如 mode)
161        key: String,
162        /// 设置值(如 verbose/concise)
163        value: String,
164    },
165
166    /// 直接修改配置文件中的某个字段
167    #[command(alias = "chg")]
168    Change {
169        /// section 名称
170        part: String,
171        /// 字段名
172        field: String,
173        /// 新值
174        value: String,
175    },
176
177    /// 清屏
178    #[command(alias = "cls")]
179    Clear,
180
181    // ========== 系统信息 ==========
182    /// 版本信息
183    #[command(alias = "v")]
184    Version,
185
186    /// 帮助信息
187    #[command(alias = "h")]
188    Help,
189
190    /// 退出(交互模式)
191    #[command(aliases = ["q", "quit"])]
192    Exit,
193
194    /// 生成 shell 补全脚本
195    Completion {
196        /// shell 类型: zsh, bash, fish
197        shell: Option<String>,
198    },
199}