1use clap::{Parser, Subcommand};
2
3use crate::output::prelude::OutputFormat;
4
5#[derive(Parser)]
6#[command(
7 name = "rco",
8 version,
9 author,
10 about = "Rusty Commit - AI-powered commit message generator written in Rust 🚀🤖",
11 after_help = r#"EXAMPLES:
12 # Generate a commit message for staged changes
13 rco
14
15 # Generate with context and copy to clipboard
16 rco -c "Focus on auth changes" --clipboard
17
18 # Generate 3 variations and skip confirmation
19 rco -g 3 -y
20
21 # Use GitMoji format
22 rco --fgm
23
24 # Authenticate with Anthropic
25 rco auth login
26
27 # Setup git hooks
28 rco hook set
29
30 # Generate PR description
31 rco pr generate --base main
32
33 # Generate shell completions
34 rco completions bash
35 rco completions zsh
36 rco completions fish
37"#
38)]
39pub struct Cli {
40 #[command(subcommand)]
41 pub command: Option<Commands>,
42
43 #[command(flatten)]
44 pub global: GlobalOptions,
45}
46
47#[derive(Parser, Clone)]
48pub struct GlobalOptions {
49 #[arg(long = "fgm", default_value = "false")]
51 pub full_gitmoji: bool,
52
53 #[arg(short = 'c', long = "context")]
55 pub context: Option<String>,
56
57 #[arg(short = 'y', long = "yes", default_value = "false")]
59 pub skip_confirmation: bool,
60
61 #[arg(long = "show-prompt", default_value = "false")]
63 pub show_prompt: bool,
64
65 #[arg(long = "no-pre-hooks", default_value = "false")]
67 pub no_pre_hooks: bool,
68
69 #[arg(long = "no-post-hooks", default_value = "false")]
71 pub no_post_hooks: bool,
72
73 #[arg(short = 'g', long = "generate", default_value = "1")]
75 pub generate_count: u8,
76
77 #[arg(short = 'C', long = "clipboard", default_value = "false")]
79 pub clipboard: bool,
80
81 #[arg(short = 'x', long = "exclude")]
83 pub exclude_files: Option<Vec<String>>,
84
85 #[arg(long = "timing", default_value = "false")]
87 pub timing: bool,
88
89 #[arg(long = "strip-thinking", default_value = "false")]
91 pub strip_thinking: bool,
92
93 #[arg(long = "print", default_value = "false")]
95 pub print_message: bool,
96
97 #[arg(long = "output-format", default_value = "pretty")]
99 pub output_format: OutputFormat,
100}
101
102#[derive(Parser)]
103pub struct SetupCommand {
104 #[arg(long, default_value = "false")]
106 pub defaults: bool,
107}
108
109#[derive(Subcommand)]
110pub enum Commands {
111 Config(ConfigCommand),
113
114 Hook(HookCommand),
116
117 #[command(name = "commitlint")]
119 CommitLint(CommitLintCommand),
120
121 Auth(AuthCommand),
123
124 Mcp(McpCommand),
126
127 Update(UpdateCommand),
129
130 Pr(PrCommand),
132
133 Model(ModelCommand),
135
136 Setup(SetupCommand),
138
139 Completions(CompletionsCommand),
141}
142
143#[derive(Parser)]
144pub struct PrCommand {
145 #[command(subcommand)]
146 pub action: PrAction,
147}
148
149#[derive(Subcommand)]
150pub enum PrAction {
151 Generate {
153 #[arg(short, long)]
155 base: Option<String>,
156 },
157 Browse {
159 #[arg(short, long)]
161 base: Option<String>,
162 },
163}
164
165#[derive(Parser)]
166pub struct ConfigCommand {
167 #[command(subcommand)]
168 pub action: ConfigAction,
169}
170
171#[derive(Subcommand)]
172pub enum ConfigAction {
173 Set {
175 #[arg(required = true)]
177 pairs: Vec<String>,
178 },
179 Get {
181 key: String,
183 },
184 Reset {
186 #[arg(long)]
188 all: bool,
189 keys: Vec<String>,
191 },
192 Status,
194 Describe,
196 AddProvider {
198 #[arg(short, long)]
200 provider: Option<String>,
201 #[arg(short, long)]
203 alias: Option<String>,
204 },
205 ListAccounts,
207 UseAccount {
209 alias: String,
211 },
212 RemoveAccount {
214 alias: String,
216 },
217 ShowAccount {
219 alias: Option<String>,
221 },
222}
223
224#[derive(Parser)]
225pub struct HookCommand {
226 #[command(subcommand)]
227 pub action: HookAction,
228}
229
230#[derive(Subcommand)]
231pub enum HookAction {
232 PrepareCommitMsg,
234 CommitMsg,
236 Unset,
238 Precommit {
240 #[arg(long)]
242 set: bool,
243 #[arg(long)]
245 unset: bool,
246 },
247}
248
249#[derive(Parser)]
250pub struct CommitLintCommand {
251 #[arg(long)]
253 pub set: bool,
254}
255
256#[derive(Parser)]
257pub struct AuthCommand {
258 #[command(subcommand)]
259 pub action: AuthAction,
260}
261
262#[derive(Subcommand)]
263pub enum AuthAction {
264 Login,
266 Logout,
268 Status,
270}
271
272#[derive(Parser)]
273pub struct McpCommand {
274 #[command(subcommand)]
275 pub action: McpAction,
276}
277
278#[derive(Subcommand)]
279pub enum McpAction {
280 Server {
282 #[arg(short, long, default_value = "3000")]
284 port: Option<u16>,
285 },
286 Stdio,
288}
289
290#[derive(Parser)]
291pub struct UpdateCommand {
292 #[arg(short, long)]
294 pub check: bool,
295
296 #[arg(short, long)]
298 pub force: bool,
299
300 #[arg(short, long)]
302 pub version: Option<String>,
303}
304
305#[derive(Parser)]
306pub struct ModelCommand {
307 #[arg(long = "list")]
309 pub list: bool,
310 #[arg(short, long)]
312 pub provider: Option<String>,
313}
314
315#[derive(Parser)]
316pub struct CompletionsCommand {
317 #[arg(value_enum)]
319 pub shell: clap_complete::Shell,
320}