pub mod git; pub mod hg; pub mod darcs; pub mod pijul; use std::ffi::OsStr; use std::fmt::Display; use std::path::Path; use std::str::FromStr; use util::StrSkip; #[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub enum Vcs { Git, Hg, Darcs, Pijul, } impl Vcs { pub fn do_init>(self, path: P) -> ::Result<()> { match self { Vcs::Git => git::init(path), Vcs::Hg => hg::init(path), Vcs::Darcs => darcs::initialize(path), Vcs::Pijul => pijul::init(path), } } pub fn do_clone(self, path: P, url: U, args: I) -> ::Result<()> where P: AsRef, U: AsRef, I: IntoIterator, S: AsRef + Display, { match self { Vcs::Git => git::clone(url, path, args), Vcs::Hg => hg::clone(url, path, args), Vcs::Darcs => darcs::clone(url, path, args), Vcs::Pijul => pijul::clone(url, path, args), } } pub fn get_remote_url>(self, path: P) -> ::Result> { match self { Vcs::Git => git::get_remote_url(path), Vcs::Hg => hg::get_remote_url(path), _ => Err("This VCS has not supported yet".to_owned().into()), } } } pub fn detect_from_path>(path: P) -> Option { [".git", ".hg", "_darcs", ".pijul"] .into_iter() .find(|vcs| path.as_ref().join(vcs).exists()) .and_then(|s| s.skip(1).parse().ok()) } impl FromStr for Vcs { type Err = String; fn from_str(s: &str) -> ::std::result::Result { match s { "git" => Ok(Vcs::Git), "hg" => Ok(Vcs::Hg), "darcs" => Ok(Vcs::Darcs), "pijul" => Ok(Vcs::Pijul), s => Err(format!("{} is invalid string", s)), } } }