]>
Commit | Line | Data |
---|---|---|
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 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 | ||
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 | })?; | |
29 | ||
30 | Command::new(COMMAND) | |
31 | .arg("--version") | |
32 | .stdout(Stdio::null()) | |
33 | .stderr(Stdio::null()) | |
34 | .status() | |
35 | .map_err(|_| Error::new(Other, "Publishing requires rsync"))?; | |
36 | ||
37 | Command::new(COMMAND) | |
38 | .arg("-r") | |
39 | .arg(format!( | |
40 | "{}/", | |
41 | &configuration.archive_output_directory.display() | |
42 | )) | |
43 | .arg(input.as_str()) | |
44 | .stdout(Stdio::null()) | |
45 | .stderr(Stdio::null()) | |
46 | .status() | |
47 | .map_err(|_| Error::new(Other, "Rsync failed to publish."))?; | |
48 | Ok(()) | |
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 { | |
60 | "<destination>\tPublishes the archive to a remote host" | |
61 | } | |
62 | } |