]> git.r.bdr.sh - rbdr/blog/blob - src/command/publish_archive.rs
Use sequence format for deb
[rbdr/blog] / src / command / publish_archive.rs
1 use std::io::{Error, ErrorKind::Other, 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
23 .ok_or_else(|| Error::new(Other, "You must provide a location to publish the archive"))?;
24
25 Command::new(COMMAND)
26 .arg("--version")
27 .stdout(Stdio::null())
28 .stderr(Stdio::null())
29 .status()
30 .map_err(|_| Error::new(Other, "Publishing requires rsync"))?;
31
32
33 Command::new(COMMAND)
34 .arg("-r")
35 .arg(format!("{}/", &configuration.archive_output_directory.display()))
36 .arg(input.as_str())
37 .stdout(Stdio::null())
38 .stderr(Stdio::null())
39 .status()
40 .map_err(|_| Error::new(Other, "Rsync failed to publish."))?;
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-archive"
50 }
51
52 fn help(&self) -> &'static str {
53 "<destination>\tPublishes the archive to a remote host"
54 }
55 }