use clap::{SubCommand, ArgMatches, Arg};
use commands::{BasicOptions, StaticSubcommand};
use error::Error;
use std::io::{stderr, Write};
use std::process::exit;
use rand;
pub fn invocation() -> StaticSubcommand {
return SubCommand::with_name("diff")
.about("show what would be recorded if record were called")
.arg(Arg::with_name("repository")
.long("repository")
.help("The repository to show, defaults to the current directory.")
.takes_value(true)
.required(false))
.arg(Arg::with_name("branch")
.long("branch")
.help("The branch to show, defaults to the current branch.")
.takes_value(true)
.required(false))
.arg(Arg::with_name("prefix")
.help("Prefix to start from")
.takes_value(true)
.multiple(true))
}
pub fn run(args: &ArgMatches) -> Result<(), Error> {
let opts = BasicOptions::from_args(args)?;
let repo = opts.open_and_grow_repo(409600)?;
let mut txn = repo.mut_txn_begin(rand::thread_rng())?;
let (changes, _) = txn.record(&opts.branch(), &opts.repo_root, None)?;
try!(super::ask::print_status(&txn, &changes));
Ok(())
}
pub fn explain(res: Result<(), Error>) {
match res {
Ok(_) => (),
Err(e) => {
write!(stderr(), "error: {}", e).unwrap();
exit(1)
}
}
}