fix: resolve module structure issues by separating CLI and git modules
Some checks failed
CI / build (push) Failing after 45s
Some checks failed
CI / build (push) Failing after 45s
- 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
This commit is contained in:
@@ -2,9 +2,9 @@ use anyhow::Result;
|
||||
use colored::Colorize;
|
||||
use dialoguer::{Confirm, Select};
|
||||
|
||||
use super::analyzer::{analyze_changes, get_all_commit_types, CommitType};
|
||||
use super::generator::{generate_alternative_messages, generate_message};
|
||||
use super::git::{GitRepo, StagedChanges};
|
||||
use crate::analyzer::{analyze_changes, get_all_commit_types, CommitType};
|
||||
use crate::generator::{generate_alternative_messages, generate_message};
|
||||
use crate::git::{GitRepo, StagedChanges};
|
||||
|
||||
pub fn select_commit_type(suggested: CommitType) -> Result<CommitType> {
|
||||
let all_types = get_all_commit_types();
|
||||
@@ -13,10 +13,10 @@ pub fn select_commit_type(suggested: CommitType) -> Result<CommitType> {
|
||||
let suggested_idx = all_types.iter().position(|t| *t == suggested).unwrap_or(0);
|
||||
|
||||
println!("{}", "\nSuggested commit type:".bold().green());
|
||||
println!(" {}", format!("{}", suggested).green().bold());
|
||||
println!(" {}", format!("{}", suggested).green().bold());
|
||||
|
||||
let selection = Select::with_theme(&dialoguer::theme::ColorfulTheme::default())
|
||||
.with_prompt("Select commit type (use ↑↓ to navigate, Enter to confirm)")
|
||||
.with_prompt("Select commit type (use ↑/↓ to navigate, Enter to confirm)")
|
||||
.items(&type_names)
|
||||
.default(suggested_idx)
|
||||
.interact()?;
|
||||
@@ -26,12 +26,12 @@ pub fn select_commit_type(suggested: CommitType) -> Result<CommitType> {
|
||||
|
||||
pub fn confirm_message(message: &str, alternatives: &[String]) -> Result<(bool, Option<String>)> {
|
||||
println!("{}", "\nGenerated commit message:".bold().green());
|
||||
println!("\n{}", message.bright_white().on_blue());
|
||||
println!("\n{}\n", message.bright_white().on_blue());
|
||||
|
||||
if !alternatives.is_empty() {
|
||||
println!("{}", "Alternative messages:".bold().yellow());
|
||||
for (i, alt) in alternatives.iter().enumerate() {
|
||||
println!(" {}: {}", (i + 1).to_string().yellow(), alt);
|
||||
println!(" {}: {}", (i + 1).to_string().yellow(), alt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,10 @@ pub fn confirm_message(message: &str, alternatives: &[String]) -> Result<(bool,
|
||||
|
||||
if edit_prompt {
|
||||
let edited = dialoguer::Editor::new()
|
||||
.edit(&format!("\n# Edit your commit message below:\n{}", message))
|
||||
.edit(&format!(
|
||||
"\n# Edit your commit message below:\n{}\n",
|
||||
message
|
||||
))
|
||||
.map_err(|e| anyhow::anyhow!("Failed to open editor: {}", e))?;
|
||||
|
||||
match edited {
|
||||
@@ -82,14 +85,14 @@ pub fn interactive_commit(
|
||||
suggested_type: CommitType,
|
||||
staged: &StagedChanges,
|
||||
) -> Result<Option<String>> {
|
||||
let selected_type = if git_repo.has_config() {
|
||||
let selected_type = if git_repo.has_config()? {
|
||||
select_commit_type(suggested_type)?
|
||||
} else {
|
||||
suggested_type
|
||||
};
|
||||
|
||||
let analysis = analyze_changes(staged);
|
||||
let analysis = super::analyzer::AnalysisResult {
|
||||
let analysis = AnalysisResult {
|
||||
commit_type: selected_type,
|
||||
..analysis
|
||||
};
|
||||
@@ -116,15 +119,15 @@ pub fn print_staged_summary(staged: &StagedChanges) {
|
||||
println!("{}", "\nStaged changes:".bold().green());
|
||||
for file in &staged.files {
|
||||
let status_str = match file.status {
|
||||
super::git::FileStatus::Added => "A".green(),
|
||||
super::git::FileStatus::Deleted => "D".red(),
|
||||
super::git::FileStatus::Modified => "M".yellow(),
|
||||
super::git::FileStatus::Renamed => "R".cyan(),
|
||||
super::git::FileStatus::Unknown => "?".white(),
|
||||
crate::git::FileStatus::Added => "A".green(),
|
||||
crate::git::FileStatus::Deleted => "D".red(),
|
||||
crate::git::FileStatus::Modified => "M".yellow(),
|
||||
crate::git::FileStatus::Renamed => "R".cyan(),
|
||||
crate::git::FileStatus::Unknown => "?".white(),
|
||||
};
|
||||
|
||||
println!(
|
||||
" {} {:>5} {:>5} {}",
|
||||
" {} {:>6} {:>6} {}",
|
||||
status_str,
|
||||
format!("+{}", file.additions).green(),
|
||||
format!("-{}", file.deletions).red(),
|
||||
|
||||
Reference in New Issue
Block a user