X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/a9c6be4162bd15bd41ba3605127b56cb1eb32f32..b17907faf8d9693cef94a6048d802bd4ced9102f:/src/command/publish.rs?ds=sidebyside diff --git a/src/command/publish.rs b/src/command/publish.rs index 881c987..388792f 100644 --- a/src/command/publish.rs +++ b/src/command/publish.rs @@ -1,5 +1,8 @@ -use std::io::Result; use crate::configuration::Configuration; +use std::io::{Error, ErrorKind::Other, Result}; +use std::process::{Command, Stdio}; + +const COMMAND: &str = "rsync"; pub struct Publish; @@ -14,9 +17,34 @@ impl super::Command for Publish { vec![] } - fn execute(&self, input: Option<&String>, _: &Configuration, _: &String) -> Result<()> { - println!("Publish: {:?}!", input); - return Ok(()) + fn execute( + &self, + input: Option<&String>, + configuration: &Configuration, + _: &str, + ) -> Result<()> { + let input = input + .ok_or_else(|| Error::new(Other, "You must provide a location to publish the blog"))?; + + Command::new(COMMAND) + .arg("--version") + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .map_err(|_| Error::new(Other, "Publishing requires rsync"))?; + + Command::new(COMMAND) + .arg("-r") + .arg(format!( + "{}/", + &configuration.blog_output_directory.display() + )) + .arg(input.as_str()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .map_err(|_| Error::new(Other, "Rsync failed to publish."))?; + Ok(()) } fn after_dependencies(&self) -> Vec> {