X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/2f579cf4c0d8ff95af78103783c7ca8f951cc797..b17907faf8d9693cef94a6048d802bd4ced9102f:/src/command/publish_archive.rs?ds=sidebyside diff --git a/src/command/publish_archive.rs b/src/command/publish_archive.rs index 6b98b1a..96dda86 100644 --- a/src/command/publish_archive.rs +++ b/src/command/publish_archive.rs @@ -1,4 +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 PublishArchive; @@ -13,9 +17,35 @@ impl super::Command for PublishArchive { vec![] } - fn execute(&self, input: Option<&String>) -> Result<()> { - println!("Publish Archive: {:?}!", 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 archive") + })?; + + 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.archive_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> {