]> git.r.bdr.sh - rbdr/blog/blame_incremental - src/command/publish.rs
Do CI
[rbdr/blog] / src / command / publish.rs
... / ...
CommitLineData
1use std::io::{Error, ErrorKind::Other, Result};
2use crate::configuration::Configuration;
3use std::process::{Command, Stdio};
4
5const COMMAND: &str = "rsync";
6
7pub struct Publish;
8
9impl Publish {
10 pub fn new() -> Self {
11 Publish
12 }
13}
14
15impl super::Command for Publish {
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 blog"))?;
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.blog_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"
50 }
51
52 fn help(&self) -> &'static str {
53 "<destination>\t\tPublishes the blog to a remote host"
54 }
55}