]> git.r.bdr.sh - rbdr/blog/blobdiff - src/command/publish.rs
Add mac
[rbdr/blog] / src / command / publish.rs
index d8ca9498bc8fc4c883a6392c9cc832fc1ee9afa0..34ca0d28388fec1a414a1ba79b609aa6e26ffe68 100644 (file)
@@ -1,4 +1,8 @@
-use std::io::Result;
+use std::io::{Error, ErrorKind::Other, Result};
+use crate::configuration::Configuration;
+use std::process::{Command, Stdio};
+
+const COMMAND: &str = "rsync";
 
 pub struct Publish;
 
@@ -13,8 +17,27 @@ impl super::Command for Publish {
         vec![]
     }
 
-    fn execute(&self, input: Option<&String>) -> Result<()> {
-        println!("Publish: {:?}!", input);
+    fn execute(&self, input: Option<&String>, configuration: &Configuration, _: &String) -> 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."))?;
         return Ok(())
     }
 
@@ -27,6 +50,6 @@ impl super::Command for Publish {
     }
 
     fn help(&self) -> &'static str {
-        "<destination>\tPublishes the blog to a remote host."
+        "<destination>\t\tPublishes the blog to a remote host"
     }
 }