|
@ -10,7 +10,7 @@ use structopt::StructOpt; |
|
|
use log::{debug, info, trace};
|
|
|
use log::{debug, info, trace};
|
|
|
|
|
|
|
|
|
// Local Imports
|
|
|
// Local Imports
|
|
|
use crate::cache::File as FileCache;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::errors::*;
|
|
|
use crate::errors::*;
|
|
|
use crate::gitignore::Gitignore;
|
|
|
use crate::gitignore::Gitignore;
|
|
|
use crate::helpers;
|
|
|
use crate::helpers;
|
|
@ -58,7 +58,8 @@ pub struct CliOpts { |
|
|
cmd: Command,
|
|
|
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)]
|
|
|
#[derive(StructOpt, Debug)]
|
|
|
pub enum Command {
|
|
|
pub enum Command {
|
|
|
/// Add a line to the gitignore
|
|
|
/// Add a line to the gitignore
|
|
@ -69,6 +70,8 @@ pub enum Command { |
|
|
/// Download a gitignore for a language
|
|
|
/// Download a gitignore for a language
|
|
|
Get {
|
|
|
Get {
|
|
|
/// The language for which the gitignore should be downloaded
|
|
|
/// 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,
|
|
|
lang: String,
|
|
|
},
|
|
|
},
|
|
|
/// List all available templates that can be downloaded
|
|
|
/// 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);
|
|
|
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()?;
|
|
|
tmpl.load_content()?;
|
|
|
|
|
|
cache.set(lang, &tmpl)?;
|
|
|
|
|
|
tmpl
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
root.push(".gitignore");
|
|
|
root.push(".gitignore");
|
|
|
tmpl.write_to(&root)?;
|
|
|
tmpl.write_to(&root)?;
|
|
|
trace!("Wrote template to file");
|
|
|
trace!("Wrote template to file");
|
|
|