]> git.r.bdr.sh - rbdr/blog/blob - src/command/publish_archive.rs
075421f0ac1b25c1f2738724f656832af6692363
[rbdr/blog] / src / command / publish_archive.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 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(&self, input: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> {
21
22 let input = input.expect("You must provide a location to publish the archive");
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.archive_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-archive"
49 }
50
51 fn help(&self) -> &'static str {
52 "<destination>\tPublishes the archive to a remote host"
53 }
54 }