1use std::env;
4
5use clap::Parser;
6use gitcc_core::{
7 build_changelog, commit_history, ChangelogBuildOptions, Config, StatusShow,
8 TEMPLATE_CHANGELOG_STD,
9};
10
11use crate::{info, warn};
12
13#[derive(Debug, Parser)]
15pub struct ChangelogArgs {
16 #[arg(long)]
18 pub all: bool,
19 #[arg(long)]
21 pub unreleased: bool,
22}
23
24pub fn run(args: ChangelogArgs) -> anyhow::Result<()> {
26 let cwd = env::current_dir()?;
27 let cfg = Config::load_from_fs(&cwd)?;
28 let cfg = if let Some(c) = cfg {
29 c
30 } else {
31 info!("using default config");
32 Config::default()
33 };
34
35 let status = gitcc_core::git_status(&cwd, StatusShow::IndexAndWorkdir)?;
37 if !status.is_empty() {
38 warn!("repo is dirty");
39 }
40
41 let history = commit_history(&cwd, &cfg)?;
43 let changelog_opts = ChangelogBuildOptions {
44 origin_name: None,
45 all: args.all,
46 next_version: if args.unreleased {
47 None
48 } else {
49 Some(history.next_version_str())
50 },
51 };
52 let changelog = build_changelog(&cwd, &cfg, &history, Some(changelog_opts))?;
53 let changelog_str = changelog.render(TEMPLATE_CHANGELOG_STD)?;
54 println!("{changelog_str}");
55
56 Ok(())
57}