45 lines
1.0 KiB
Rust
45 lines
1.0 KiB
Rust
use std::process::exit;
|
|
use colored::*;
|
|
use gclone::{first_arg, Cache, Error, Result};
|
|
|
|
fn main() {
|
|
if let Err(e) = main_result() {
|
|
eprintln!("{}", e);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
fn main_result() -> Result<()> {
|
|
let request = first_arg()?;
|
|
main_with_cache(&request, true)
|
|
}
|
|
|
|
fn main_with_cache(request: &str, regen: bool) -> Result<()> {
|
|
|
|
let (cache, just_generated) = match Cache::read() {
|
|
Ok(c) => (c, false),
|
|
Err(_) => (Cache::generate(), true),
|
|
};
|
|
|
|
let only_match = match cache.find_interactive(&request) {
|
|
|
|
Err(Error::NoSuchDirectory) if regen && ! just_generated => {
|
|
eprintln!("{} {}",
|
|
"warning:".bold().yellow(),
|
|
"directory not found, regenerating cache...".bold());
|
|
let cache = Cache::generate();
|
|
cache.write()?;
|
|
return main_with_cache(request, false);
|
|
},
|
|
|
|
Err(e) => return Err(e),
|
|
Ok(x) => x,
|
|
};
|
|
|
|
println!("{}", only_match);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|