1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
use crate::constants;
use clap::{Parser, Subcommand};
use constants::VERSION;
/// work-copilot (j) - 快捷命令行工具 🚀
#[derive(Parser, Debug)]
#[command(name = "j", version = VERSION, about = "快捷命令行工具", long_about = None)]
#[command(disable_help_subcommand = true)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<SubCmd>,
/// 当没有匹配到子命令时,收集所有剩余参数(用于别名打开)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
pub args: Vec<String>,
}
#[derive(Subcommand, Debug)]
pub enum SubCmd {
// ========== 别名管理 ==========
/// 设置别名(路径/URL)
#[command(alias = "s")]
Set {
/// 别名
alias: String,
/// 路径或 URL(支持空格,多个参数会拼接)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
path: Vec<String>,
},
/// 删除别名
#[command(alias = "rm")]
Remove {
/// 要删除的别名
alias: String,
},
/// 重命名别名
#[command(alias = "rn")]
Rename {
/// 原别名
alias: String,
/// 新别名
new_alias: String,
},
/// 修改别名对应的路径
#[command(alias = "mf")]
Modify {
/// 别名
alias: String,
/// 新路径或 URL
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
path: Vec<String>,
},
// ========== 分类标记 ==========
/// 标记别名为指定分类(browser/editor/vpn/outer_url/script)
#[command(alias = "t")]
Tag {
/// 别名
alias: String,
/// 分类: browser, editor, vpn, outer_url, script
category: String,
},
/// 解除别名的分类标记
#[command(alias = "ut")]
Untag {
/// 别名
alias: String,
/// 分类: browser, editor, vpn, outer_url, script
category: String,
},
// ========== 列表 ==========
/// 列出别名
#[command(alias = "ls")]
List {
/// 指定 section(可选,如 path/inner_url/all 等)
part: Option<String>,
},
/// 在指定分类中查找别名
#[command(alias = "find")]
Contain {
/// 要搜索的别名
alias: String,
/// 可选的分类列表(逗号分隔,如 path,browser,vpn)
containers: Option<String>,
},
// ========== 日报系统 ==========
/// 写入日报
#[command(aliases = ["r"])]
Report {
/// 日报内容(支持多个参数拼接)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
content: Vec<String>,
},
/// 日报元数据操作(new/sync/push/pull)
#[command(name = "reportctl", alias = "rctl")]
Reportctl {
/// 操作: new / sync / push / pull
action: String,
/// 可选参数(new/sync 时为日期,push 时为 commit message)
arg: Option<String>,
},
/// 查看日报最近 N 行
#[command(alias = "c")]
Check {
/// 行数(默认 5)
line_count: Option<String>,
},
/// 在日报中搜索关键字
#[command(aliases = ["select", "look", "sch"])]
Search {
/// 行数或 "all"
line_count: String,
/// 搜索关键字
target: String,
/// 可选: -f 或 -fuzzy 启用模糊匹配
#[arg(allow_hyphen_values = true)]
fuzzy: Option<String>,
},
// ========== 待办备忘录 ==========
/// 待办备忘录(无参数进入 TUI 界面)
#[command(alias = "td")]
Todo {
/// 子命令: list(输出待办)/ add <content>(快速添加),无参数进入 TUI
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
content: Vec<String>,
},
// ========== AI 对话 ==========
/// AI 对话(无参数进入 TUI 界面,有参数快速提问)
#[command(alias = "ai")]
Chat {
/// 延续上一个会话(使用最近一次 oneshot 会话)
#[arg(long = "continue", short = 'c')]
cont: bool,
/// 指定要延续的会话 ID
#[arg(long)]
session: Option<String>,
/// 启用远程控制(手机扫码控制)
#[arg(long)]
remote: bool,
/// 远程控制监听端口
#[arg(long, default_value = "9390")]
port: u16,
/// 消息内容(支持多个参数拼接)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
content: Vec<String>,
},
// ========== 脚本 ==========
/// 创建脚本
#[command(alias = "sc")]
Script {
/// 脚本名称
name: String,
/// 脚本内容(可选,不提供则打开 TUI 编辑器)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
content: Vec<String>,
},
// ========== 计时器 ==========
/// 倒计时器
Time {
/// 功能名称(目前支持: countdown)
function: String,
/// 参数(时长,如 30s、5m、1h)
arg: String,
},
// ========== 系统设置 ==========
/// 日志模式设置
Log {
/// 设置项名称(如 mode)
key: String,
/// 设置值(如 verbose/concise)
value: String,
},
/// 直接修改配置文件中的某个字段
#[command(alias = "cfg")]
Config {
/// section 名称
part: String,
/// 字段名
field: String,
/// 新值
value: String,
},
/// 清屏
#[command(alias = "cls")]
Clear,
// ========== 系统信息 ==========
/// 版本信息
#[command(alias = "v")]
Version,
/// 帮助信息
#[command(alias = "h")]
Help,
/// 退出(交互模式)
#[command(aliases = ["q", "quit"])]
Exit,
/// 生成 shell 补全脚本
Completion {
/// shell 类型: zsh, bash, fish
shell: Option<String>,
},
// ========== 自更新 ==========
/// 更新 j-cli 到最新版本
#[command(alias = "up")]
Update {
/// 仅检查版本,不更新
#[arg(short, long)]
check: bool,
/// 是否在交互模式下调用(更新成功后自动重启)
#[arg(skip)]
interactive: bool,
},
// ========== Markdown / 笔记本 ==========
/// Markdown 笔记管理(无参数打开 TUI,传文件路径直接编辑,传子命令执行操作)
#[command(alias = "markdown")]
Md {
/// 子命令(list/search/delete/open/rename)、笔记标题、或文件路径
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// notebook 的别名(等同 md)
#[command(alias = "nb", hide = true)]
Notebook {
/// 子命令或笔记标题
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
}