Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): allow configuring output file from config #829

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions git-cliff-core/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ mod test {
replace: Some(String::from("exciting")),
replace_command: None,
}]),
output: None,
},
git: GitConfig {
conventional_commits: Some(true),
Expand Down
2 changes: 2 additions & 0 deletions git-cliff-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions git-cliff-core/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
9 changes: 5 additions & 4 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 \
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)?;
}

Expand Down
4 changes: 4 additions & 0 deletions website/docs/configuration/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Loading