]> git.r.bdr.sh - rbdr/blog/blob - src/command/publish.rs
207b45ddeda0cb56d913ffa863a0ee30ad2a12a7
[rbdr/blog] / src / command / publish.rs
1 use std::io::Result;
2 use crate::configuration::Configuration;
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(&self, input: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> {
21
22 let input = input.expect("You must provide a location to publish the blog");
23
24 Command::new(COMMAND)
25 .arg("--version")
26 .stdout(Stdio::null())
27 .stderr(Stdio::null())
28 .status()
29 .expect("Publishing requires rsync");
30
31
32 Command::new(COMMAND)
33 .arg("-r")
34 .arg(format!("{}/", &configuration.blog_output_directory.display()))
35 .arg(input.as_str())
36 .stdout(Stdio::null())
37 .stderr(Stdio::null())
38 .status()
39 .expect("Publishing requires rsync");
40 return Ok(())
41 }
42
43 fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {
44 vec![]
45 }
46
47 fn command(&self) -> &'static str {
48 "publish"
49 }
50
51 fn help(&self) -> &'static str {
52 "<destination>\t\tPublishes the blog to a remote host"
53 }
54 }