]>
Commit | Line | Data |
---|---|---|
50f53dc4 | 1 | use std::io::{Error, ErrorKind::Other, Result}; |
a9c6be41 | 2 | use crate::configuration::Configuration; |
6352ebb0 RBR |
3 | use std::process::{Command, Stdio}; |
4 | ||
5 | const COMMAND: &str = "rsync"; | |
d620665f RBR |
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 | ||
6352ebb0 RBR |
20 | fn execute(&self, input: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> { |
21 | ||
50f53dc4 RBR |
22 | let input = input |
23 | .ok_or_else(|| Error::new(Other, "You must provide a location to publish the blog"))?; | |
6352ebb0 RBR |
24 | |
25 | Command::new(COMMAND) | |
26 | .arg("--version") | |
27 | .stdout(Stdio::null()) | |
28 | .stderr(Stdio::null()) | |
29 | .status() | |
50f53dc4 | 30 | .map_err(|_| Error::new(Other, "Publishing requires rsync"))?; |
6352ebb0 RBR |
31 | |
32 | ||
33 | Command::new(COMMAND) | |
34 | .arg("-r") | |
35 | .arg(format!("{}/", &configuration.blog_output_directory.display())) | |
36 | .arg(input.as_str()) | |
37 | .stdout(Stdio::null()) | |
38 | .stderr(Stdio::null()) | |
39 | .status() | |
50f53dc4 | 40 | .map_err(|_| Error::new(Other, "Rsync failed to publish."))?; |
d620665f RBR |
41 | return Ok(()) |
42 | } | |
43 | ||
44 | fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> { | |
45 | vec![] | |
46 | } | |
47 | ||
48 | fn command(&self) -> &'static str { | |
49 | "publish" | |
50 | } | |
51 | ||
52 | fn help(&self) -> &'static str { | |
2f579cf4 | 53 | "<destination>\t\tPublishes the blog to a remote host" |
d620665f RBR |
54 | } |
55 | } |