use anyhow::{Context, bail};
use clap::Args;
use tracing::{debug, instrument};
use scrat_core::config::Config;
use scrat_core::notes::{self, PreviewNotesOptions};
#[derive(Args, Debug, Default)]
pub struct NotesArgs {
#[arg(long, value_name = "TAG")]
pub from: Option<String>,
#[arg(long, value_name = "VERSION")]
pub version: Option<String>,
#[arg(long, value_name = "FILE")]
pub template: Option<String>,
#[arg(long)]
pub no_deps: bool,
#[arg(long)]
pub no_stats: bool,
}
#[instrument(name = "cmd_notes", skip_all)]
pub fn cmd_notes(
args: NotesArgs,
global_json: bool,
config: &Config,
cwd: &camino::Utf8Path,
) -> anyhow::Result<()> {
debug!("rendering release notes preview");
let options = PreviewNotesOptions {
from: args.from,
version: args.version,
template: args.template,
no_deps: args.no_deps,
no_stats: args.no_stats,
};
let result =
notes::preview_notes(cwd, config, options).context("failed to render release notes")?;
if result.notes.trim().is_empty() {
bail!("git-cliff produced empty output — check that there are unreleased commits");
}
if global_json {
println!("{}", serde_json::to_string_pretty(&result)?);
} else {
print!("{}", result.notes);
}
Ok(())
}