use clap::{SubCommand, Arg, ArgMatches};
use std::path::Path;
use commands::StaticSubcommand;
use libpijul::Repository;
use libpijul::fs_representation::{pristine_dir, find_repo_root};
use commands::get_wd;
use error::Error;
pub struct Params<'a> {
pub repository: Option<&'a Path>,
}
pub fn invocation() -> StaticSubcommand {
return SubCommand::with_name("check")
.about("Check the sanity of a repository")
.arg(Arg::with_name("repository")
.index(1)
.help("The repository to check, defaults to the current directory.")
.required(false));
}
pub fn parse_args<'a>(args: &'a ArgMatches) -> Params<'a> {
Params { repository: args.value_of("repository").and_then(|x| Some(Path::new(x))) }
}
pub fn run(args: &Params) -> Result<(), Error> {
let wd = try!(get_wd(args.repository));
match find_repo_root(&wd) {
Some(ref repo_base) => {
let _repository = Repository::open(&pristine_dir(&repo_base)).unwrap();
println!("Your repo looks alright Ma'am/Sir");
Ok(())
}
None => Err(Error::NotInARepository),
}
}