Skip to content

Commit

Permalink
feat(changelog): add output flag
Browse files Browse the repository at this point in the history
Use `convco changelog -o CHANGELOG.md` to write the output to the file instead of stdout.
  • Loading branch information
hdevalke committed Jan 12, 2023
1 parent d5cc605 commit ca37fe4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
7 changes: 5 additions & 2 deletions src/cmd/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Write> = 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(())
}
}

0 comments on commit ca37fe4

Please sign in to comment.