diff --git a/src/config.rs b/src/config.rs index 0dad1a1..1458a7a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -46,7 +46,7 @@ impl Config { .arg( Arg::with_name("only match") .short("o") - .help("Only print matched text") + .help("Only print matched text"), ) .get_matches(); diff --git a/src/main.rs b/src/main.rs index bbb6d8d..fb2ded5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use rack::filematch::*; use std::fs::{self, DirEntry, File}; use std::io; use std::io::prelude::*; -use std::path::Path; +use std::path::{Path, PathBuf}; extern crate term; @@ -12,13 +12,14 @@ fn main() { let search_path = &config.path; let path = if search_path.starts_with('/') { - Path::new(search_path) + PathBuf::from(search_path) } else { - let p: &'static str = Box::leak(Box::new(String::from("./") + search_path)); - Path::new(p) + let mut path = String::from("./"); + path.push_str(search_path); + PathBuf::from(path) }; - let results = traverse_dir(&config, path, Option::None, |config, path| { + let results = traverse_dir(&config, &path, Option::None, |config, path| { check_file(config, path) }); match results { @@ -30,7 +31,7 @@ fn main() { fn traverse_dir( config: &Config, - dir: &Path, + dir: &PathBuf, gitignore_entries: Option>, operation: fn(&Config, &Path) -> io::Result, ) -> io::Result> { @@ -71,18 +72,15 @@ fn traverse_dir( // TODO: Should borrow gitignore instead of cloning.. let mut results = traverse_dir(&config, &entry.path(), Some(gitignore.clone()), operation)?; - let has_results = results - .iter() - .filter(|mat| !mat.matches.is_empty()) - .count() - > 0; + let has_results = results.iter().filter(|mat| !mat.matches.is_empty()).count() > 0; if has_results { matches.append(&mut results); } } else { if config.use_gitignore { - let should_ignore: Option<&String> = gitignore.iter().find(|&line| path.contains(&line.clone())); + let should_ignore: Option<&String> = + gitignore.iter().find(|&line| path.contains(&line.clone())); if !should_ignore.unwrap_or(&String::from("")).is_empty() || entry.path().to_str().unwrap().contains("/.git")