commit_wizard/
lib.rs

1pub mod adapters;
2pub mod application;
3pub mod cli;
4pub mod domain;
5pub mod ports;
6
7use anyhow::Result;
8use clap::Parser;
9
10use cli::{Cli, Command};
11
12use adapters::git::{cmd::CmdGit, noop::NoopGit};
13use adapters::prompt::tty::TtyPrompt;
14use application::usecases::CreateCommit;
15use ports::git::CommitOptions;
16
17fn run_commit(allow_empty: bool, dry_run: bool) -> Result<()> {
18    let opts = CommitOptions { allow_empty };
19
20    // pick adapter based on global dry-run
21    let git: Box<dyn ports::git::GitPort> = if dry_run {
22        Box::new(NoopGit::default())
23    } else {
24        Box::new(CmdGit::default())
25    };
26
27    let uc = CreateCommit::new(TtyPrompt::default(), git);
28    uc.run(&opts)
29}
30
31pub fn run_cli() -> Result<()> {
32    let cli = Cli::parse();
33    let dry_run = cli.global.dry_run;
34
35    match cli.command {
36        Command::Commit { allow_empty } => run_commit(allow_empty, dry_run)?,
37    }
38
39    Ok(())
40}