diff --git a/config/cliff.toml b/config/cliff.toml index 4d368fa85c..fc5def181c 100644 --- a/config/cliff.toml +++ b/config/cliff.toml @@ -38,6 +38,8 @@ trim = true postprocessors = [ # { pattern = '', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL ] +# output file path +# output = "test.md" [git] # parse the commits based on https://www.conventionalcommits.org diff --git a/git-cliff-core/src/changelog.rs b/git-cliff-core/src/changelog.rs index 7cf31155c5..6ff289242e 100644 --- a/git-cliff-core/src/changelog.rs +++ b/git-cliff-core/src/changelog.rs @@ -670,6 +670,7 @@ mod test { replace: Some(String::from("exciting")), replace_command: None, }]), + output: None, }, git: GitConfig { conventional_commits: Some(true), diff --git a/git-cliff-core/src/config.rs b/git-cliff-core/src/config.rs index a39af6a476..3afcc2b99e 100644 --- a/git-cliff-core/src/config.rs +++ b/git-cliff-core/src/config.rs @@ -79,6 +79,8 @@ pub struct ChangelogConfig { pub trim: Option, /// Changelog postprocessors. pub postprocessors: Option>, + /// Output file path. + pub output: Option, } /// Git configuration diff --git a/git-cliff-core/tests/integration_test.rs b/git-cliff-core/tests/integration_test.rs index 45add262dd..fc166c3bd5 100644 --- a/git-cliff-core/tests/integration_test.rs +++ b/git-cliff-core/tests/integration_test.rs @@ -41,6 +41,7 @@ fn generate_changelog() -> Result<()> { footer: Some(String::from("eoc - end of changelog")), trim: None, postprocessors: None, + output: None, }; let git_config = GitConfig { conventional_commits: Some(true), diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index bafb9b918d..85d4e8215a 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -424,6 +424,7 @@ pub fn run(mut args: Opt) -> Result<()> { } // Update the configuration based on command line arguments and vice versa. + let output = args.output.clone().or(config.changelog.output.clone()); match args.strip { Some(Strip::Header) => { config.changelog.header = None; @@ -445,9 +446,9 @@ pub fn run(mut args: Opt) -> Result<()> { ))); } } - if args.output.is_some() && + if output.is_some() && args.prepend.is_some() && - args.output.as_ref() == args.prepend.as_ref() + output.as_ref() == args.prepend.as_ref() { return Err(Error::ArgumentError(String::from( "'-o' and '-p' can only be used together if they point to different \ @@ -595,7 +596,7 @@ pub fn run(mut args: Opt) -> Result<()> { }; // Print the result. - let mut out: Box = if let Some(path) = &args.output { + let mut out: Box = if let Some(path) = &output { if path == Path::new("-") { Box::new(io::stdout()) } else { @@ -631,7 +632,7 @@ pub fn run(mut args: Opt) -> Result<()> { let mut out = io::BufWriter::new(File::create(path)?); changelog.prepend(changelog_before, &mut out)?; } - if args.output.is_some() || args.prepend.is_none() { + if output.is_some() || args.prepend.is_none() { changelog.generate(&mut out)?; } diff --git a/website/docs/configuration/changelog.md b/website/docs/configuration/changelog.md index 90387ebc41..8636eafbfd 100644 --- a/website/docs/configuration/changelog.md +++ b/website/docs/configuration/changelog.md @@ -55,3 +55,7 @@ It is useful for adding indentation to the template for readability, as shown [i An array of commit postprocessors for manipulating the changelog before outputting. Can e.g. be used for replacing commit author with GitHub usernames. Internally postprocessors and preprocessors are the same. See [commit_preprocessors](/docs/configuration/git#commit_preprocessors) for more detail and examples, it uses the same syntax. + +### output + +Output file path for the changelog. You can also use the `--output` argument to override this value.