summaryrefslogtreecommitdiff
path: root/src/summain.rs
blob: ce9cf0fe95691c58f8807108e4991100b99128b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use std::path::Path;
use std::process::Command;

#[derive(Debug, thiserror::Error)]
pub enum SummainError {
    #[error("failed to run summain: {0}")]
    Run(std::io::Error),
}

pub fn summain(root: &Path) -> Result<String, SummainError> {
    let output = Command::new("summain")
        .arg(".")
        .current_dir(root)
        .output()
        .map_err(SummainError::Run)?;
    if output.status.code() != Some(0) {
        eprintln!("{}", String::from_utf8_lossy(&output.stdout));
        eprintln!("{}", String::from_utf8_lossy(&output.stderr));
        std::process::exit(1);
    }

    Ok(String::from_utf8_lossy(&output.stdout)
        .to_owned()
        .to_string())
}