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