Some checks failed
CI / build (push) Has been cancelled
- Removed duplicated git module code from cli.rs - Created dedicated git.rs module with GitRepo, StagedChanges, ChangedFile, FileStatus definitions - Updated all modules (analyzer, generator, prompt) to import from super::git - Fixed module organization to resolve compilation errors
90 lines
2.9 KiB
Rust
90 lines
2.9 KiB
Rust
use crate::analyzer::CommitType;
|
|
use clap::{Parser, ValueEnum};
|
|
|
|
#[derive(Debug, Clone, ValueEnum)]
|
|
pub enum CommitTypeCli {
|
|
Feat,
|
|
Fix,
|
|
Docs,
|
|
Style,
|
|
Refactor,
|
|
Test,
|
|
Chore,
|
|
Build,
|
|
Ci,
|
|
Perf,
|
|
}
|
|
|
|
#[derive(Debug, Parser)]
|
|
#[command(name = "auto-commit")]
|
|
#[command(author, version, about, long_about = None)]
|
|
pub struct Args {
|
|
#[arg(long, help = "Preview the commit message without committing")]
|
|
pub dry_run: bool,
|
|
|
|
#[arg(long, short, help = "Override the detected commit type")]
|
|
pub type_override: Option<CommitTypeCli>,
|
|
|
|
#[arg(long, short, help = "Override the detected scope")]
|
|
pub scope_override: Option<String>,
|
|
|
|
#[arg(long, help = "Skip interactive prompts and use auto-detected values")]
|
|
pub no_interactive: bool,
|
|
|
|
#[arg(long, help = "Show verbose output including staged changes")]
|
|
pub verbose: bool,
|
|
}
|
|
|
|
impl std::str::FromStr for CommitTypeCli {
|
|
type Err = String;
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
match s.to_lowercase().as_str() {
|
|
"feat" | "feature" => Ok(CommitTypeCli::Feat),
|
|
"fix" | "bug" => Ok(CommitTypeCli::Fix),
|
|
"docs" | "documentation" => Ok(CommitTypeCli::Docs),
|
|
"style" => Ok(CommitTypeCli::Style),
|
|
"refactor" => Ok(CommitTypeCli::Refactor),
|
|
"test" | "tests" => Ok(CommitTypeCli::Test),
|
|
"chore" => Ok(CommitTypeCli::Chore),
|
|
"build" | "ci" => Ok(CommitTypeCli::Build),
|
|
"perf" | "performance" => Ok(CommitTypeCli::Perf),
|
|
_ => Err(format!("Unknown commit type: {}", s)),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<CommitTypeCli> for CommitType {
|
|
fn from(cli_type: CommitTypeCli) -> Self {
|
|
match cli_type {
|
|
CommitTypeCli::Feat => CommitType::Feat,
|
|
CommitTypeCli::Fix => CommitType::Fix,
|
|
CommitTypeCli::Docs => CommitType::Docs,
|
|
CommitTypeCli::Style => CommitType::Style,
|
|
CommitTypeCli::Refactor => CommitType::Refactor,
|
|
CommitTypeCli::Test => CommitType::Test,
|
|
CommitTypeCli::Chore => CommitType::Chore,
|
|
CommitTypeCli::Build => CommitType::Build,
|
|
CommitTypeCli::Ci => CommitType::Ci,
|
|
CommitTypeCli::Perf => CommitType::Perf,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for CommitTypeCli {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
CommitTypeCli::Feat => write!(f, "feat"),
|
|
CommitTypeCli::Fix => write!(f, "fix"),
|
|
CommitTypeCli::Docs => write!(f, "docs"),
|
|
CommitTypeCli::Style => write!(f, "style"),
|
|
CommitTypeCli::Refactor => write!(f, "refactor"),
|
|
CommitTypeCli::Test => write!(f, "test"),
|
|
CommitTypeCli::Chore => write!(f, "chore"),
|
|
CommitTypeCli::Build => write!(f, "build"),
|
|
CommitTypeCli::Ci => write!(f, "ci"),
|
|
CommitTypeCli::Perf => write!(f, "perf"),
|
|
}
|
|
}
|
|
}
|