From bf032559fc722bc6346f9f897ee76743ff1eda18 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 1 Feb 2026 12:20:54 +0000 Subject: [PATCH] Initial upload: Auto Commit Message Generator with CI/CD workflow --- src/cli.rs | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/cli.rs diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..07dd93e --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,89 @@ +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, + + #[arg(long, short, help = "Override the detected scope")] + pub scope_override: Option, + + #[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 { + 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 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"), + } + } +}