diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-04-04 12:30:52 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-04-04 14:57:38 +0300 |
commit | d60b3fbf8d1840e5a1b5b088333e136616068c15 (patch) | |
tree | 6f48e856c00748f36f518c9032ddbcdd1fa7a86a /src/debian.rs | |
parent | cbeff8974a6228a44396cc924acc6fd111a5b681 (diff) | |
download | bumper-rs-d60b3fbf8d1840e5a1b5b088333e136616068c15.tar.gz |
feat: set version in debian/changelog
Diffstat (limited to 'src/debian.rs')
-rw-r--r-- | src/debian.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/debian.rs b/src/debian.rs new file mode 100644 index 0000000..d82a14a --- /dev/null +++ b/src/debian.rs @@ -0,0 +1,46 @@ +use crate::errors::BumperError; +use log::{debug, info}; +use std::path::{Path, PathBuf}; +use std::process::Command; + +pub struct Debian { + dirname: PathBuf, +} + +impl Debian { + pub fn new(dirname: &Path) -> Result<Self, BumperError> { + let changelog = dirname.join("debian/changelog"); + if changelog.exists() { + info!("directory {} contains Debian packaging", dirname.display()); + return Ok(Self { + dirname: dirname.to_path_buf(), + }); + } + debug!( + "directory {} doesn't contains Debian packaging", + dirname.display() + ); + Err(BumperError::UnknownProjectKind(dirname.to_path_buf())) + } + + pub fn set_version(&mut self, version: &str) -> Result<(), BumperError> { + let version = format!("{}-1", version); + self.dch(&["-v", &version, ""])?; + self.dch(&["-r", ""])?; + Ok(()) + } + + fn dch(&self, args: &[&str]) -> Result<(), BumperError> { + let output = Command::new("dch") + .args(args) + .current_dir(&self.dirname) + .output() + .map_err(|err| BumperError::DchInvoke(self.dirname.to_path_buf(), err))?; + if output.status.success() { + Ok(()) + } else { + let stderr = String::from_utf8_lossy(&output.stderr).into_owned(); + Err(BumperError::Dch(self.dirname.to_path_buf(), stderr)) + } + } +} |