use clap::{Arg, App, SubCommand};
use std::error::Error;
use bliss::*;
fn main() -> Result<(), Box<dyn Error>> {
let matches = App::new("bliss")
.version("1.0")
.author("Avery Wagar <ajmw.subs@gmail.com>")
.about("Ignorance is bliss! Ignore your .gitignore")
.arg(Arg::with_name("LANGUAGE")
.help("Set the languages to download .gitignores for (i.e. \"rust,python\")")
.required(false)
.index(1))
.subcommand(SubCommand::with_name("list")
.about("List supported languages"))
.subcommand(SubCommand::with_name("cache")
.about("Manage bliss cache")
.subcommand(SubCommand::with_name("clear").about("Clear bliss cache"))
.subcommand(SubCommand::with_name("update").about("Update bliss cache")))
.get_matches();
let mut bliss = Bliss::new();
if let Some(_) = matches.subcommand_matches("list") {
let langs = bliss.supported_langs()?;
println!("Supported Languages:\n========================\n{}", langs.join(", "));
}
else if let Some(matches) = matches.subcommand_matches("cache") {
if let Some(_matches) = matches.subcommand_matches("clear") {
println!("Clearing cache...");
std::fs::remove_dir_all(format!("{}/bliss", dirs::cache_dir().unwrap().to_string_lossy()))?;
std::process::exit(0);
}
else if let Some(_matches) = matches.subcommand_matches("update") {
println!("Updating cache...");
bliss.supported_langs()?;
for lang in bliss.cache.gitignores.clone().keys() {
println!("Updating {} template...", lang);
bliss.cache.gitignores.remove(lang);
bliss.get_lang_gitignore(lang);
}
}
}
else {
for lang in matches.value_of("LANGUAGE").unwrap_or("").split(" ").collect::<Vec<_>>().join("").split(",") {
if lang == "" {
println!("Try: bliss help");
break;
}
if bliss.is_supported(lang){
let ignore = bliss.get_lang_gitignore(lang);
print!("{}", ignore.unwrap());
}
}
}
bliss.cache.save()?;
Ok(())
}