use std::process::ExitCode;
use anyhow::Result;
use camino::Utf8PathBuf;
use clap::crate_version;
fn clap() -> clap::Command {
use clap::Command;
Command::new("git-cache")
.version(crate_version!())
.author("Kaspar Schleiser <kaspar@schleiser.de>")
.about("A git repository cache tool")
.infer_subcommands(true)
.arg(git_cache::clap_git_cache_dir_arg())
.subcommand(git_cache::clap_clone_command("clone"))
.subcommand(
Command::new("init").hide(true),
)
}
fn main() -> Result<ExitCode> {
let matches = clap().get_matches();
let cache_dir = Utf8PathBuf::from(&shellexpand::tilde(
matches.get_one::<Utf8PathBuf>("git_cache_dir").unwrap(),
));
match matches.subcommand() {
Some(("clone", matches)) => {
let repository = matches.get_one::<String>("repository").unwrap();
let target_path = matches.get_one::<Utf8PathBuf>("target_path").cloned();
let wanted_commit = matches.get_one::<String>("commit");
let sparse_paths = matches
.get_many::<String>("sparse-add")
.map(|v| v.into_iter().collect::<Vec<&String>>());
git_cache::clone(
cache_dir,
repository.clone(),
wanted_commit,
matches,
target_path,
sparse_paths,
)?;
}
Some(("other", _matches)) => {}
_ => {}
}
Ok(0.into())
}