borg-hive 0.0.2

Automated backups using Borg Backup
use std::borrow::Cow;
use std::process;

use shellexpand;

use errors::*;

pub fn run(args: &Vec<String>) -> Result<process::ExitStatus> {
    let args: Vec<String> = expanded_vec(args)?
        .into_iter()
        .map(|x| x.into_owned())
        .collect();

    let exit_status = process::Command::new(&args[0]).args(&args[1..]).status()?;

    if !exit_status.success() {
        bail!("command ended with {}", exit_status);
    }

    Ok(exit_status)
}

pub fn expanded_vec(v: &Vec<String>) -> Result<Vec<Cow<str>>> {
    v.iter().map(|x| expanded(x)).collect()
}

pub fn expanded<'a>(s: &'a str) -> Result<Cow<'a, str>> {
    shellexpand::full(s).chain_err(|| {
        format!("cannot perform tilde or envvar expansion on {}", s)
    })
}