4 Commits

  1. 483
      Cargo.lock
  2. 2
      Cargo.toml
  3. 15
      src/app.rs
  4. 4
      src/helpers.rs

483
Cargo.lock
File diff suppressed because it is too large
View File

2
Cargo.toml

@ -1,6 +1,6 @@
[package]
name = "gitig"
version = "0.1.4"
version = "0.2.0"
authors = ["Marcel Schneider <gitig@webschneider.org>"]
description = "A cli utility to manage gitignore files easily"
edition = "2018"

15
src/app.rs

@ -65,7 +65,10 @@ pub enum Command {
/// Add a line to the gitignore
Add {
/// The glob string that should be added
glob: String,
glob: String,
/// Add the entry to the repo local ignore file
#[structopt(short)]
local: bool,
},
/// Download a gitignore for a language
Get {
@ -87,7 +90,7 @@ pub enum Command {
}
/// Runs the command `add`
fn run_add(glob: &str) -> Result<()> {
fn run_add(glob: &str, local: bool) -> Result<()> {
trace!("running command `add` with glob '{}'", &glob);
let root = match git_dir()? {
Some(r) => r,
@ -96,7 +99,11 @@ fn run_add(glob: &str) -> Result<()> {
info!("Working with git root in {:?}", root);
let mut file_path = PathBuf::from(&root);
file_path.push(".gitignore");
if local {
file_path.push(".git/info/exclude")
} else {
file_path.push(".gitignore");
}
let gitig = Gitignore::from_path(&file_path);
gitig.add_line(glob)?;
debug!("Added '{}' to {}", glob, gitig);
@ -158,7 +165,7 @@ fn run_dump_completion(shell: Option<structopt::clap::Shell>) -> Result<()> {
/// The actual `main()`
pub fn main(opts: CliOpts) -> Result<()> {
match opts.cmd {
Command::Add { glob } => run_add(&glob)?,
Command::Add { glob, local } => run_add(&glob, local)?,
Command::Get { lang, append } => run_get(&lang, append)?,
Command::ListTemplates => run_list_templates()?,
Command::DumpCompletions { shell } => run_dump_completion(shell)?,

4
src/helpers.rs

@ -100,7 +100,7 @@ pub fn git_dir() -> Result<Option<PathBuf>> {
/// Returns a `PathBuf` to the cache root for this project
///
/// This will be either the appropriate cache dir according to XDG or as a fallback `/tmp`.
pub fn chache_root() -> PathBuf {
pub fn cache_root() -> PathBuf {
match ProjectDirs::from("org", "webschneider", env!("CARGO_PKG_NAME")) {
Some(dirs) => PathBuf::from(dirs.cache_dir()),
None => "/tmp".into(),
@ -109,7 +109,7 @@ pub fn chache_root() -> PathBuf {
/// Returns a default file cache
pub fn default_cache() -> Result<FileCache> {
let cache_root = crate::helpers::chache_root();
let cache_root = crate::helpers::cache_root();
FileCache::new(&cache_root, std::time::Duration::from_secs(60 * 24 * 2))
}

Loading…
Cancel
Save