Skip to content

Commit 8f9769a

Browse files
committed
refactor: move print_table function to utils module
- relocate print_table function from cli.rs to new utils.rs module for better code organization - update main.rs imports to reference utils::print_table - remove print_table and its test from cli.rs to eliminate redundancy Signed-off-by: mingcheng <mingcheng@apache.org>
1 parent 18f32b6 commit 8f9769a

3 files changed

Lines changed: 59 additions & 31 deletions

File tree

src/cli.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -112,34 +112,5 @@ If not specified, the current directory will be used"#,
112112
pub save: String,
113113
}
114114

115-
pub fn print_table(title: &str, content: &str) {
116-
let mut binding =
117-
tabled::builder::Builder::from_iter([["Title", title.trim()], ["Content", content.trim()]])
118-
.build();
119-
let table = binding
120-
.with(tabled::settings::Style::rounded())
121-
.with(tabled::settings::Width::wrap(120))
122-
.with(tabled::settings::Alignment::left());
123-
124-
println!("{}", table);
125-
}
126-
127115
#[cfg(test)]
128-
mod tests {
129-
use super::*;
130-
131-
#[test]
132-
fn test_print_table() {
133-
const TITLE: &str = r#"feat: bump version to 1.4.0 and update system template 🚀"#;
134-
const CONTENT: &str = r#"
135-
- Update version from 1.3.3 to 1.4.0 in Cargo.toml
136-
- Enhance system template with additional instructions
137-
- Simplify and clarify template content for better usability
138-
- Remove redundant information to streamline template
139-
- Ensure template aligns with latest commit message standards
140-
141-
Signed-off-by: mingcheng <mingcheng@apache.org>
142-
"#;
143-
print_table(TITLE, CONTENT);
144-
}
145-
}
116+
mod tests {}

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Last Modified: 2025-09-26 15:45:37
1313
*/
1414

15-
use aigitcommit::cli::{Cli, print_table};
15+
use aigitcommit::cli::Cli;
1616
use aigitcommit::git::message::GitMessage;
1717
use aigitcommit::git::repository::Repository;
1818
use aigitcommit::openai;
@@ -29,9 +29,12 @@ use std::fs::File;
2929
use std::io::Write;
3030
use std::{env, fs};
3131
use tracing::{Level, debug, trace};
32+
33+
use crate::utils::print_table;
3234
mod built_info {
3335
include!(concat!(env!("OUT_DIR"), "/built.rs"));
3436
}
37+
mod utils;
3538

3639
/// The output format for the commit message
3740
#[derive(Debug)]

src/utils.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*!
2+
* Copyright (c) 2025 Hangzhou Guanwaii Technology Co., Ltd.
3+
*
4+
* This source code is licensed under the MIT License,
5+
* which is located in the LICENSE file in the source tree's root directory.
6+
*
7+
* File: utils.rs
8+
* Author: mingcheng <mingcheng@apache.org>
9+
* File Created: 2025-10-21 11:34:11
10+
*
11+
* Modified By: mingcheng <mingcheng@apache.org>
12+
* Last Modified: 2025-10-21 17:52:45
13+
*/
14+
15+
/// Print the commit message in a table format
16+
pub fn print_table(title: &str, content: &str) {
17+
let mut binding =
18+
tabled::builder::Builder::from_iter([["Title", title.trim()], ["Content", content.trim()]])
19+
.build();
20+
let table = binding
21+
.with(tabled::settings::Style::rounded())
22+
.with(tabled::settings::Width::wrap(120))
23+
.with(tabled::settings::Alignment::left());
24+
25+
println!("{}", table);
26+
}
27+
28+
#[cfg(test)]
29+
mod tests {
30+
use super::*;
31+
32+
#[test]
33+
fn test_print_table_simple() {
34+
print_table(
35+
"Test Title",
36+
"This is a test content for the commit message.",
37+
);
38+
}
39+
40+
#[test]
41+
fn test_print_table_with_message() {
42+
const TITLE: &str = r#"feat: bump version to 1.4.0 and update system template 🚀"#;
43+
const CONTENT: &str = r#"
44+
- Update version from 1.3.3 to 1.4.0 in Cargo.toml
45+
- Enhance system template with additional instructions
46+
- Simplify and clarify template content for better usability
47+
- Remove redundant information to streamline template
48+
- Ensure template aligns with latest commit message standards
49+
50+
Signed-off-by: mingcheng <mingcheng@apache.org>
51+
"#;
52+
print_table(TITLE, CONTENT);
53+
}
54+
}

0 commit comments

Comments
 (0)