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 colored::Colorize;
|
||||||
use dialoguer::{Confirm, Select};
|
use dialoguer::{Confirm, Select};
|
||||||
|
|
||||||
use super::analyzer::{analyze_changes, get_all_commit_types, CommitType};
|
use crate::analyzer::{analyze_changes, get_all_commit_types, CommitType};
|
||||||
use super::generator::{generate_alternative_messages, generate_message};
|
use crate::generator::{generate_alternative_messages, generate_message};
|
||||||
use super::git::{GitRepo, StagedChanges};
|
use crate::git::{GitRepo, StagedChanges};
|
||||||
|
|
||||||
pub fn select_commit_type(suggested: CommitType) -> Result<CommitType> {
|
pub fn select_commit_type(suggested: CommitType) -> Result<CommitType> {
|
||||||
let all_types = get_all_commit_types();
|
let all_types = get_all_commit_types();
|
||||||
@@ -16,7 +16,7 @@ pub fn select_commit_type(suggested: CommitType) -> Result<CommitType> {
|
|||||||
println!(" {}", format!("{}", suggested).green().bold());
|
println!(" {}", format!("{}", suggested).green().bold());
|
||||||
|
|
||||||
let selection = Select::with_theme(&dialoguer::theme::ColorfulTheme::default())
|
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)
|
.items(&type_names)
|
||||||
.default(suggested_idx)
|
.default(suggested_idx)
|
||||||
.interact()?;
|
.interact()?;
|
||||||
@@ -26,7 +26,7 @@ pub fn select_commit_type(suggested: CommitType) -> Result<CommitType> {
|
|||||||
|
|
||||||
pub fn confirm_message(message: &str, alternatives: &[String]) -> Result<(bool, Option<String>)> {
|
pub fn confirm_message(message: &str, alternatives: &[String]) -> Result<(bool, Option<String>)> {
|
||||||
println!("{}", "\nGenerated commit message:".bold().green());
|
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() {
|
if !alternatives.is_empty() {
|
||||||
println!("{}", "Alternative messages:".bold().yellow());
|
println!("{}", "Alternative messages:".bold().yellow());
|
||||||
@@ -50,7 +50,10 @@ pub fn confirm_message(message: &str, alternatives: &[String]) -> Result<(bool,
|
|||||||
|
|
||||||
if edit_prompt {
|
if edit_prompt {
|
||||||
let edited = dialoguer::Editor::new()
|
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))?;
|
.map_err(|e| anyhow::anyhow!("Failed to open editor: {}", e))?;
|
||||||
|
|
||||||
match edited {
|
match edited {
|
||||||
@@ -82,14 +85,14 @@ pub fn interactive_commit(
|
|||||||
suggested_type: CommitType,
|
suggested_type: CommitType,
|
||||||
staged: &StagedChanges,
|
staged: &StagedChanges,
|
||||||
) -> Result<Option<String>> {
|
) -> Result<Option<String>> {
|
||||||
let selected_type = if git_repo.has_config() {
|
let selected_type = if git_repo.has_config()? {
|
||||||
select_commit_type(suggested_type)?
|
select_commit_type(suggested_type)?
|
||||||
} else {
|
} else {
|
||||||
suggested_type
|
suggested_type
|
||||||
};
|
};
|
||||||
|
|
||||||
let analysis = analyze_changes(staged);
|
let analysis = analyze_changes(staged);
|
||||||
let analysis = super::analyzer::AnalysisResult {
|
let analysis = AnalysisResult {
|
||||||
commit_type: selected_type,
|
commit_type: selected_type,
|
||||||
..analysis
|
..analysis
|
||||||
};
|
};
|
||||||
@@ -116,15 +119,15 @@ pub fn print_staged_summary(staged: &StagedChanges) {
|
|||||||
println!("{}", "\nStaged changes:".bold().green());
|
println!("{}", "\nStaged changes:".bold().green());
|
||||||
for file in &staged.files {
|
for file in &staged.files {
|
||||||
let status_str = match file.status {
|
let status_str = match file.status {
|
||||||
super::git::FileStatus::Added => "A".green(),
|
crate::git::FileStatus::Added => "A".green(),
|
||||||
super::git::FileStatus::Deleted => "D".red(),
|
crate::git::FileStatus::Deleted => "D".red(),
|
||||||
super::git::FileStatus::Modified => "M".yellow(),
|
crate::git::FileStatus::Modified => "M".yellow(),
|
||||||
super::git::FileStatus::Renamed => "R".cyan(),
|
crate::git::FileStatus::Renamed => "R".cyan(),
|
||||||
super::git::FileStatus::Unknown => "?".white(),
|
crate::git::FileStatus::Unknown => "?".white(),
|
||||||
};
|
};
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
" {} {:>5} {:>5} {}",
|
" {} {:>6} {:>6} {}",
|
||||||
status_str,
|
status_str,
|
||||||
format!("+{}", file.additions).green(),
|
format!("+{}", file.additions).green(),
|
||||||
format!("-{}", file.deletions).red(),
|
format!("-{}", file.deletions).red(),
|
||||||
|
|||||||
Reference in New Issue
Block a user