krankerl 0.11.0

A CLI helper to manage Nextcloud apps
Documentation
use std::fs;
use std::io;
use std::path::Path;

use failure::Error;
use git2;

use crate::error;

pub fn clone_app(src: &Path, dst: &Path) -> Result<(), Error> {
    git2::Repository::clone(
        src.as_os_str()
            .to_str()
            .expect("could not convert clone destination to str"),
        dst,
    )?;

    Ok(())
}

pub fn clear(path: &Path) -> Result<(), Error> {
    if let Err(e) = fs::remove_dir_all(path) {
        // We can safely ignore NotFound errors here
        if e.kind() != io::ErrorKind::NotFound {
            bail!(error::KrankerlError::Other {
                cause: "could not delete artifacts dir".to_string(),
            });
        }
    }
    fs::create_dir_all(path)?;
    Ok(())
}