use crate::configuration::Configuration; use std::io::{Error, Result}; use std::process::{Command, Stdio}; const COMMAND: &str = "rsync"; pub struct PublishArchive; impl PublishArchive { pub fn new() -> Self { PublishArchive } } impl super::Command for PublishArchive { fn before_dependencies(&self) -> Vec> { vec![] } fn execute( &self, input: Option<&String>, configuration: &Configuration, _: &str, ) -> Result<()> { let input = input.ok_or_else(|| { Error::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::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::other("Rsync failed to publish."))?; Ok(()) } fn after_dependencies(&self) -> Vec> { vec![] } fn command(&self) -> &'static str { "publish-archive" } fn help(&self) -> &'static str { "\tPublishes the archive to a remote host" } }