|
| 1 | +use clap::{ArgGroup, Parser, Subcommand}; |
| 2 | + |
| 3 | +/// CLI options |
| 4 | +#[derive(Parser, Debug)] |
| 5 | +#[command( |
| 6 | + name = "commitbot", |
| 7 | + version, |
| 8 | + about = "LLM-assisted Git commit message generator" |
| 9 | +)] |
| 10 | +#[command(group( |
| 11 | + ArgGroup::new("model_group") |
| 12 | + .args(["model", "no_model"]) |
| 13 | + .multiple(false) |
| 14 | +))] |
| 15 | +pub struct Cli { |
| 16 | + /// Interactive mode: classify each file and do per-file summaries |
| 17 | + #[arg(long, global = true)] |
| 18 | + pub ask: bool, |
| 19 | + |
| 20 | + /// If set, write the generated message into .git/COMMIT_EDITMSG (no commit is created) |
| 21 | + #[arg(short = 'w', long, global = true)] |
| 22 | + pub apply: bool, |
| 23 | + |
| 24 | + /// Stage all changes before generating the commit message |
| 25 | + #[arg(short, long, global = true)] |
| 26 | + pub stage: bool, |
| 27 | + |
| 28 | + /// Debug mode: log prompts, responses, token usage |
| 29 | + #[arg(long, global = true)] |
| 30 | + pub debug: bool, |
| 31 | + |
| 32 | + /// Model name to use (e.g. gpt-4o-mini). If 'none', acts like --no-model. |
| 33 | + #[arg(short, long, global = true)] |
| 34 | + pub model: Option<String>, |
| 35 | + |
| 36 | + /// Disable model calls; return dummy responses instead |
| 37 | + #[arg(long, global = true)] |
| 38 | + pub no_model: bool, |
| 39 | + |
| 40 | + /// API key (otherwise uses OPENAI_API_KEY env var) |
| 41 | + #[arg(short = 'k', long, env = "OPENAI_API_KEY", global = true)] |
| 42 | + pub api_key: Option<String>, |
| 43 | + |
| 44 | + /// Optional: a brief human description of the ticket (for commit/PR summaries) |
| 45 | + #[arg(long, global = true)] |
| 46 | + pub ticket_summary: Option<String>, |
| 47 | + |
| 48 | + /// Subcommand (e.g. 'pr') |
| 49 | + #[command(subcommand)] |
| 50 | + pub command: Option<Command>, |
| 51 | +} |
| 52 | + |
| 53 | +/// Subcommands, e.g. `commitbot pr develop` |
| 54 | +#[derive(Subcommand, Debug)] |
| 55 | +pub enum Command { |
| 56 | + /// Generate a Pull Request description by summarizing commit or PR messages |
| 57 | + Pr { |
| 58 | + /// Base branch to compare against (e.g. main or develop) |
| 59 | + base: String, |
| 60 | + |
| 61 | + /// Optional feature/source branch; defaults to current branch if omitted |
| 62 | + from: Option<String>, |
| 63 | + |
| 64 | + /// Force using PR-oriented grouping (PR numbers) instead of commits |
| 65 | + #[arg(long = "pr")] |
| 66 | + pr_mode: bool, |
| 67 | + |
| 68 | + /// Force using commit-by-commit mode instead of PR grouping |
| 69 | + #[arg(long = "commit")] |
| 70 | + commit_mode: bool, |
| 71 | + }, |
| 72 | +} |
0 commit comments