mirror of
https://github.com/orhun/git-cliff.git
synced 2024-09-11 06:55:38 +03:00
feat(changelog): support prepending entries to an existing changelog
This commit is contained in:
parent
90fb613159
commit
4e3735256e
@ -35,6 +35,9 @@ pub struct Opt {
|
||||
/// Sets the tag for the latest version.
|
||||
#[structopt(short, long, env, value_name = "TAG", allow_hyphen_values = true)]
|
||||
pub tag: Option<String>,
|
||||
/// Prepend entries to the given changelog from stdin.
|
||||
#[structopt(short, long)]
|
||||
pub prepend: bool,
|
||||
/// Processes the commits starting from the latest tag.
|
||||
#[structopt(short, long)]
|
||||
pub latest: bool,
|
||||
|
@ -91,4 +91,18 @@ impl<'a> Changelog<'a> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Generate changelog and prepend it to the given changelog.
|
||||
pub fn prepend<W: Write>(
|
||||
&self,
|
||||
mut changelog: String,
|
||||
out: &mut W,
|
||||
) -> Result<()> {
|
||||
if let Some(header) = &self.config.changelog.header {
|
||||
changelog = changelog.replacen(header, "", 1);
|
||||
}
|
||||
self.generate(out)?;
|
||||
write!(out, "{}", changelog)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,10 @@ use git_cliff_core::error::Result;
|
||||
use git_cliff_core::release::Release;
|
||||
use git_cliff_core::repo::Repository;
|
||||
use std::env;
|
||||
use std::io;
|
||||
use std::io::{
|
||||
self,
|
||||
Read,
|
||||
};
|
||||
use structopt::StructOpt;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
@ -27,6 +30,8 @@ fn main() -> Result<()> {
|
||||
if args.strip {
|
||||
config.changelog.header = None;
|
||||
config.changelog.footer = None;
|
||||
} else if args.prepend {
|
||||
config.changelog.footer = None;
|
||||
}
|
||||
|
||||
let repository =
|
||||
@ -77,5 +82,12 @@ fn main() -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
Changelog::new(releases, &config)?.generate(&mut io::stdout())
|
||||
let changelog = Changelog::new(releases, &config)?;
|
||||
if args.prepend {
|
||||
let mut buffer = String::new();
|
||||
io::stdin().read_to_string(&mut buffer)?;
|
||||
changelog.prepend(buffer, &mut io::stdout())
|
||||
} else {
|
||||
changelog.generate(&mut io::stdout())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user