]> git.r.bdr.sh - rbdr/blog/blob - src/command/publish.rs
Deal with all lints
[rbdr/blog] / src / command / publish.rs
1 use crate::configuration::Configuration;
2 use std::io::{Error, ErrorKind::Other, Result};
3 use std::process::{Command, Stdio};
4
5 const COMMAND: &str = "rsync";
6
7 pub struct Publish;
8
9 impl Publish {
10 pub fn new() -> Self {
11 Publish
12 }
13 }
14
15 impl super::Command for Publish {
16 fn before_dependencies(&self) -> Vec<Box<dyn super::Command>> {
17 vec![]
18 }
19
20 fn execute(
21 &self,
22 input: Option<&String>,
23 configuration: &Configuration,
24 _: &str,
25 ) -> Result<()> {
26 let input = input
27 .ok_or_else(|| Error::new(Other, "You must provide a location to publish the blog"))?;
28
29 Command::new(COMMAND)
30 .arg("--version")
31 .stdout(Stdio::null())
32 .stderr(Stdio::null())
33 .status()
34 .map_err(|_| Error::new(Other, "Publishing requires rsync"))?;
35
36 Command::new(COMMAND)
37 .arg("-r")
38 .arg(format!(
39 "{}/",
40 &configuration.blog_output_directory.display()
41 ))
42 .arg(input.as_str())
43 .stdout(Stdio::null())
44 .stderr(Stdio::null())
45 .status()
46 .map_err(|_| Error::new(Other, "Rsync failed to publish."))?;
47 Ok(())
48 }
49
50 fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {
51 vec![]
52 }
53
54 fn command(&self) -> &'static str {
55 "publish"
56 }
57
58 fn help(&self) -> &'static str {
59 "<destination>\t\tPublishes the blog to a remote host"
60 }
61 }