From ca37fe4a3771f8903600366c6ab680455495a606 Mon Sep 17 00:00:00 2001 From: Hannes De Valkeneer <2261239+hdevalke@users.noreply.github.com> Date: Thu, 5 Jan 2023 22:05:08 +0100 Subject: [PATCH] feat(changelog): add output flag Use `convco changelog -o CHANGELOG.md` to write the output to the file instead of stdout. --- src/cli.rs | 3 +++ src/cmd/changelog.rs | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 70f442c..2e16d95 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -130,6 +130,9 @@ pub struct ChangelogCommand { /// If a semantic version is given, the title will be prefixed. #[clap(short, long, default_value = "Unreleased")] pub unreleased: String, + /// Path to write the changelog to. + #[clap(short, long, default_value = "-")] + pub output: PathBuf, } #[derive(Debug, Parser)] diff --git a/src/cmd/changelog.rs b/src/cmd/changelog.rs index 19509e3..ed19674 100644 --- a/src/cmd/changelog.rs +++ b/src/cmd/changelog.rs @@ -391,8 +391,11 @@ impl ChangelogCommand { impl Command for ChangelogCommand { fn exec(&self, config: Config) -> anyhow::Result<()> { - let stdout = std::io::stdout().lock(); - self.write(config, stdout)?; + let out: Box = match self.output.as_path() { + p if p.to_string_lossy() == "-" => Box::new(std::io::stdout().lock()), + p => Box::new(std::fs::File::create(p)?), + }; + self.write(config, out)?; Ok(()) } }