|
|
@ -10,7 +10,7 @@ use structopt::StructOpt; |
|
|
|
use log::{debug, info, trace};
|
|
|
|
|
|
|
|
// Local Imports
|
|
|
|
use crate::cache::File as FileCache;
|
|
|
|
|
|
|
|
use crate::errors::*;
|
|
|
|
use crate::gitignore::Gitignore;
|
|
|
|
use crate::helpers;
|
|
|
@ -58,7 +58,8 @@ pub struct CliOpts { |
|
|
|
cmd: Command,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Subcommands
|
|
|
|
/// gitig lets you easily start with a fresh gitignore from a template and adds new lines as you
|
|
|
|
/// wish
|
|
|
|
#[derive(StructOpt, Debug)]
|
|
|
|
pub enum Command {
|
|
|
|
/// Add a line to the gitignore
|
|
|
@ -69,6 +70,8 @@ pub enum Command { |
|
|
|
/// Download a gitignore for a language
|
|
|
|
Get {
|
|
|
|
/// The language for which the gitignore should be downloaded
|
|
|
|
///
|
|
|
|
/// A list with all available languages and projects can be printed with `list-templates`.
|
|
|
|
lang: String,
|
|
|
|
},
|
|
|
|
/// List all available templates that can be downloaded
|
|
|
@ -102,12 +105,19 @@ fn run_get(lang: &str) -> Result<()> { |
|
|
|
};
|
|
|
|
info!("Working with git root in {:?}", root);
|
|
|
|
|
|
|
|
let mut tmpls = helpers::get_templates()?;
|
|
|
|
let tmpl: &mut Template =
|
|
|
|
tmpls.get(lang).ok_or_else(|| ErrorKind::TemplateNotFound(lang.to_string()))?;
|
|
|
|
debug!("Found a template for {}", lang);
|
|
|
|
let cache = helpers::default_cache()?;
|
|
|
|
let tmpl: Template = if cache.exists(lang) {
|
|
|
|
debug!("Found a template for {} in cache", lang);
|
|
|
|
cache.get(lang)?
|
|
|
|
} else {
|
|
|
|
let tmpls = helpers::get_templates()?;
|
|
|
|
let mut tmpl =
|
|
|
|
tmpls.get(lang).ok_or_else(|| ErrorKind::TemplateNotFound(lang.to_string()))?.clone();
|
|
|
|
tmpl.load_content()?;
|
|
|
|
cache.set(lang, &tmpl)?;
|
|
|
|
tmpl
|
|
|
|
};
|
|
|
|
|
|
|
|
tmpl.load_content()?;
|
|
|
|
root.push(".gitignore");
|
|
|
|
tmpl.write_to(&root)?;
|
|
|
|
trace!("Wrote template to file");
|
|
|
|