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    // ========== AI 对话 ==========
139    /// AI 对话(无参数进入 TUI 界面,有参数快速提问)
140    #[command(alias = "ai")]
141    Chat {
142        /// 消息内容(支持多个参数拼接)
143        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
144        content: Vec<String>,
145    },
146
147    // ========== 脚本 ==========
148    /// 创建脚本
149    Concat {
150        /// 脚本名称
151        name: String,
152        /// 脚本内容(可选,不提供则打开 TUI 编辑器)
153        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
154        content: Vec<String>,
155    },
156
157    // ========== 计时器 ==========
158    /// 倒计时器
159    Time {
160        /// 功能名称(目前支持: countdown)
161        function: String,
162        /// 参数(时长,如 30s、5m、1h)
163        arg: String,
164    },
165
166    // ========== 系统设置 ==========
167    /// 日志模式设置
168    Log {
169        /// 设置项名称(如 mode)
170        key: String,
171        /// 设置值(如 verbose/concise)
172        value: String,
173    },
174
175    /// 直接修改配置文件中的某个字段
176    #[command(alias = "chg")]
177    Change {
178        /// section 名称
179        part: String,
180        /// 字段名
181        field: String,
182        /// 新值
183        value: String,
184    },
185
186    /// 清屏
187    #[command(alias = "cls")]
188    Clear,
189
190    // ========== 系统信息 ==========
191    /// 版本信息
192    #[command(alias = "v")]
193    Version,
194
195    /// 帮助信息
196    #[command(alias = "h")]
197    Help,
198
199    /// 退出(交互模式)
200    #[command(aliases = ["q", "quit"])]
201    Exit,
202
203    // ========== 语音转文字 ==========
204    /// 语音转文字(录音 → Whisper 离线转写)
205    #[command(alias = "vc")]
206    Voice {
207        /// 操作: 默认录音转写,download 下载模型
208        #[arg(default_value = "")]
209        action: String,
210        /// 复制转写结果到剪贴板
211        #[arg(short = 'c', long = "copy")]
212        copy: bool,
213        /// 指定模型大小: tiny, base, small, medium, large
214        #[arg(short = 'm', long = "model")]
215        model: Option<String>,
216    },
217
218    /// 生成 shell 补全脚本
219    Completion {
220        /// shell 类型: zsh, bash, fish
221        shell: Option<String>,
222    },
223}