Repository: orhun/git-cliff (language: python)

Issue:
Add output file configuration option
### Is there an existing issue or pull request for this?

- [X] I have searched the existing issues and pull requests

### Feature description

Where I work, it is the common case for us to want to generate and regenerate our CHANGELOG.md docs. Currently, to actually generate a document with git-cliff, we always have to pass it the `--output CHANGELOG.md` argument. This gets tedious to have to type out every time. It also means that, if we happen to typo the file name, we have to rename the file and delete the original (if regenerating).

### Desired solution

Create an `output-file` option that would go under the `[changelog]` section in the `cliff.toml` file that behaves the same as the `--output` CLI argument.

### Alternatives considered

I was not able to discern an alternative solution for this issue.

### Additional context

_No response_


Discussion / hints:
Thanks for opening your first issue at **git-cliff**! Be sure to follow the issue template! ⛰️


Fix patch:
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 = '<REPO>', 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 06b77a252c..2c8ea3af8a 100644
--- a/git-cliff-core/src/changelog.rs
+++ b/git-cliff-core/src/changelog.rs
@@ -652,6 +652,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 5949d332e9..e455197fc2 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<bool>,
 	/// Changelog postprocessors.
 	pub postprocessors: Option<Vec<TextProcessor>>,
+	/// Output file path.
+	pub output:         Option<PathBuf>,
 }
 
 /// Git configuration
diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs
index ea8dcb2299..135d095d20 100644
--- a/git-cliff/src/lib.rs
+++ b/git-cliff/src/lib.rs
@@ -416,6 +416,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;
@@ -437,9 +438,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 \
@@ -580,7 +581,7 @@ pub fn run(mut args: Opt) -> Result<()> {
 	};
 
 	// Print the result.
-	let mut out: Box<dyn io::Write> = if let Some(path) = &args.output {
+	let mut out: Box<dyn io::Write> = if let Some(path) = &output {
 		if path == Path::new("-") {
 			Box::new(io::stdout())
 		} else {
@@ -616,7 +617,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.


Test patch:
diff --git a/git-cliff-core/tests/integration_test.rs b/git-cliff-core/tests/integration_test.rs
index 58141a93b3..4e1ced473e 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),