58 lines
1.1 KiB
Rust
58 lines
1.1 KiB
Rust
#[macro_use]
|
|
extern crate log;
|
|
|
|
use std::path::PathBuf;
|
|
use std::process::exit;
|
|
|
|
use gclone::git::{clone, parse_url, GCLONE_PATH};
|
|
use gclone::{first_arg, Cache, Result};
|
|
|
|
fn help() {
|
|
print!(include_str!("../assets/help.txt"));
|
|
}
|
|
|
|
fn main_result() -> Result<()> {
|
|
// Init beautylog
|
|
beautylog::init(log::LevelFilter::Info).ok();
|
|
|
|
// Parse args
|
|
let url = first_arg()?;
|
|
|
|
if url == "-h" || url == "--help" {
|
|
return Ok(help());
|
|
}
|
|
|
|
let url = if url.ends_with(".git") {
|
|
&url[0..url.len() - 4]
|
|
} else {
|
|
&url
|
|
};
|
|
|
|
let (server, owner, repo) = parse_url(&url)?;
|
|
|
|
// Build path
|
|
let mut path = PathBuf::from(&*GCLONE_PATH);
|
|
path.push(&server);
|
|
path.push(&owner);
|
|
path.push(&repo);
|
|
|
|
// Clone repository
|
|
info!("{} {}{}", "cloning", url, "...");
|
|
clone(&url, &path)?;
|
|
info!("{}", "done!");
|
|
|
|
// Append to cache
|
|
let mut cache = Cache::read_or_generate();
|
|
cache.append(path.display().to_string());
|
|
cache.write()?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn main() {
|
|
if let Err(e) = main_result() {
|
|
error!("{}", e);
|
|
exit(1);
|
|
}
|
|
}
|