use clap::{Args as ClapArgs, ValueEnum};
use crate::{
cli::CliResult,
core::{context::Context, usecases::changelog},
engine::models::policy::changelog::ChangelogOutputFormat,
};
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum FileFormat {
Markdown,
Json,
}
impl From<FileFormat> for ChangelogOutputFormat {
fn from(value: FileFormat) -> Self {
match value {
FileFormat::Markdown => Self::Markdown,
FileFormat::Json => Self::Json,
}
}
}
#[derive(Debug, Clone, ClapArgs)]
#[command(
about = "Generate or update a changelog from Conventional Commit history",
long_about = "Generate or update a changelog from Conventional Commit history.\n\n\
By default the changes since the latest version tag are written as an \"Unreleased\" \
section (or under --next-tag) above the existing releases. Use --all to rebuild every \
release from the tag history, or --from/--to for a single custom range. Global --force \
recreates the file instead of updating it, and --dry-run previews without writing."
)]
pub struct Args {
#[arg(long)]
pub all: bool,
#[arg(long)]
pub from: Option<String>,
#[arg(long, default_value = "HEAD")]
pub to: String,
#[arg(long, value_name = "PATH")]
pub output: Option<String>,
#[arg(long, value_enum, value_name = "FORMAT")]
pub output_format: Option<FileFormat>,
#[arg(long)]
pub group_by_scope: bool,
#[arg(long, value_name = "VERSION")]
pub next_tag: Option<String>,
#[arg(long)]
pub include_non_cc: bool,
#[arg(long)]
pub prereleases: bool,
}
pub async fn run(ctx: &Context, args: Args) -> CliResult<()> {
changelog::create::run(
ctx,
changelog::create::Options {
all: args.all,
from: args.from,
to: args.to,
output: args.output,
format: args.output_format.map(Into::into),
group_by_scope: args.group_by_scope,
next_tag: args.next_tag,
include_non_cc: args.include_non_cc,
prereleases: args.prereleases,
},
)
}