]> git.r.bdr.sh - rbdr/blog/blobdiff - src/command/publish_archive.rs
Deal with all lints
[rbdr/blog] / src / command / publish_archive.rs
index 075421f0ac1b25c1f2738724f656832af6692363..96dda861fdc31a9b515a6cfddd969e512629a87a 100644 (file)
@@ -1,5 +1,5 @@
-use std::io::Result;
 use crate::configuration::Configuration;
 use crate::configuration::Configuration;
+use std::io::{Error, ErrorKind::Other, Result};
 use std::process::{Command, Stdio};
 
 const COMMAND: &str = "rsync";
 use std::process::{Command, Stdio};
 
 const COMMAND: &str = "rsync";
@@ -17,27 +17,35 @@ impl super::Command for PublishArchive {
         vec![]
     }
 
         vec![]
     }
 
-    fn execute(&self, input: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> {
-
-        let input = input.expect("You must provide a location to publish the archive");
+    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()
 
         Command::new(COMMAND)
             .arg("--version")
             .stdout(Stdio::null())
             .stderr(Stdio::null())
             .status()
-            .expect("Publishing requires rsync");
-
+            .map_err(|_| Error::new(Other, "Publishing requires rsync"))?;
 
         Command::new(COMMAND)
             .arg("-r")
 
         Command::new(COMMAND)
             .arg("-r")
-            .arg(format!("{}/", &configuration.archive_output_directory.display()))
+            .arg(format!(
+                "{}/",
+                &configuration.archive_output_directory.display()
+            ))
             .arg(input.as_str())
             .stdout(Stdio::null())
             .stderr(Stdio::null())
             .status()
             .arg(input.as_str())
             .stdout(Stdio::null())
             .stderr(Stdio::null())
             .status()
-            .expect("Publishing requires rsync");
-        return Ok(())
+            .map_err(|_| Error::new(Other, "Rsync failed to publish."))?;
+        Ok(())
     }
 
     fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {
     }
 
     fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {