1use std::env;
4
5use clap::Parser;
6use colored::Colorize;
7use gitcc_core::Config;
8
9use crate::{info, new_line};
10
11#[derive(Debug, Parser)]
13pub struct LogArgs {}
14
15pub fn run(_args: LogArgs) -> anyhow::Result<()> {
17 new_line!();
18
19 let cwd = env::current_dir()?;
20 let config = Config::load_from_fs(&cwd)?;
21 let config = if let Some(c) = config {
22 c
23 } else {
24 info!("using default config");
25 Config::default()
26 };
27
28 let history = gitcc_core::commit_history(&cwd, &config)?;
29 for c in history.commits.iter().rev() {
30 println!("{}{}", "commit: ".blue().bold(), c.id.to_string().bold());
31 if let Some(tag) = &c.tag {
32 println!("{}{}", "tag: ".magenta(), tag.name.bold());
33 }
34 println!("{}{}", "date: ".cyan(), c.date);
35 println!(
36 "{}{} <{}>",
37 "author: ".cyan(),
38 c.author_name,
39 c.author_email
40 );
41 println!("{}", c.raw_message);
48 println!();
49 }
50
51 Ok(())
52}