use error::Result;
use git2::Repository;
use std::{fs, io};
use util::cd2root;
fn theme(repo: &str) -> Result<()> {
cd2root()?;
if let Err(e) = fs::remove_dir_all("theme") {
if e.kind() != io::ErrorKind::NotFound {
return Err(e.into());
}
}
let mut path = String::new();
if github_like(repo) {
path.push_str("https://github.com/");
}
path.push_str(repo);
Repository::clone(&path, "theme")?;
Ok(())
}
fn github_like(repo: &str) -> bool {
repo.chars().filter(|&c| c == '/').count() == 1 &&
!repo.starts_with('/') && !repo.ends_with('/')
}
pub fn execute(repo: &str) {
match theme(repo) {
Ok(()) => info!("Theme changed!"),
Err(e) => error!("Theme change failed: {}.", e),
}
}