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 { 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)) } } }