]>
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 PublishArchive; | |
8 | ||
9 | impl PublishArchive { | |
10 | pub fn new() -> Self { | |
11 | PublishArchive | |
12 | } | |
13 | } | |
14 | ||
15 | impl super::Command for PublishArchive { | |
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<()> { | |
26 | let input = input.ok_or_else(|| { | |
27 | Error::new(Other, "You must provide a location to publish the archive") | |
28 | })?; | |
6352ebb0 RBR |
29 | |
30 | Command::new(COMMAND) | |
31 | .arg("--version") | |
32 | .stdout(Stdio::null()) | |
33 | .stderr(Stdio::null()) | |
34 | .status() | |
50f53dc4 | 35 | .map_err(|_| Error::new(Other, "Publishing requires rsync"))?; |
6352ebb0 | 36 | |
6352ebb0 RBR |
37 | Command::new(COMMAND) |
38 | .arg("-r") | |
d7fef30a RBR |
39 | .arg(format!( |
40 | "{}/", | |
41 | &configuration.archive_output_directory.display() | |
42 | )) | |
6352ebb0 RBR |
43 | .arg(input.as_str()) |
44 | .stdout(Stdio::null()) | |
45 | .stderr(Stdio::null()) | |
46 | .status() | |
50f53dc4 | 47 | .map_err(|_| Error::new(Other, "Rsync failed to publish."))?; |
d7fef30a | 48 | Ok(()) |
d620665f RBR |
49 | } |
50 | ||
51 | fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> { | |
52 | vec![] | |
53 | } | |
54 | ||
55 | fn command(&self) -> &'static str { | |
56 | "publish-archive" | |
57 | } | |
58 | ||
59 | fn help(&self) -> &'static str { | |
2f579cf4 | 60 | "<destination>\tPublishes the archive to a remote host" |
d620665f RBR |
61 | } |
62 | } |