diff --git a/src/main.rs b/src/main.rs index dbddfde..5a75ae2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,12 +6,7 @@ extern crate rust_util; mod opt; mod local_util; -use std::{ - cell::RefCell, - path::Path, - time::SystemTime, -}; - +use std::{ cell::RefCell, path::Path, time::SystemTime, }; use opt::*; use rust_util::{ iff, @@ -27,15 +22,27 @@ const EMPTY: &str = ""; const VERSION: &str = env!("CARGO_PKG_VERSION"); const GIT_HASH: &str = env!("GIT_HASH"); +#[derive(Debug)] +struct MatchLine { + line_number: usize, + line_string: String, +} + +impl MatchLine { + fn new(line_number: usize, line_string: String) -> MatchLine { + MatchLine { line_number, line_string, } + } +} + fn print_version() { println!(r#"finding {} - {} -Copyright (C) 2019 Hatter Jiang. +Copyright (C) 2019-2020 Hatter Jiang. License MIT Written by Hatter Jiang"#, VERSION, &GIT_HASH[0..7]); } -pub fn clear_n_print_message(mt: MessageType, message: &str) { +fn clear_n_print_message(mt: MessageType, message: &str) { print_lastline(EMPTY); print_message(mt, message); } @@ -47,11 +54,9 @@ fn find_huge_files(options: &Options, dir_path: &Path) { walk_dir(&dir_path, &|_, _| (/* do not process error */), &|p| { total_file_count_cell.replace_with(|&mut c| c + 1); match p.metadata() { - Err(err) => { - if options.verbose { - if let Some(p_str) = p.to_str() { - clear_n_print_message(MessageType::WARN, &format!("Read file {} meta failed: {}", p_str, err)); - } + Err(err) => if options.verbose { + if let Some(p_str) = p.to_str() { + clear_n_print_message(MessageType::WARN, &format!("Read file {} meta failed: {}", p_str, err)); } }, Ok(metadata) => { @@ -83,19 +88,6 @@ fn find_huge_files(options: &Options, dir_path: &Path) { get_display_size(huge_file_size_cell.into_inner() as i64))); } - -#[derive(Debug)] -struct MatchLine { - line_number: usize, - line_string: String, -} - -impl MatchLine { - fn new(line_number: usize, line_string: String) -> MatchLine { - MatchLine { line_number, line_string, } - } -} - fn match_lines(tag: &str, content: &str, options: &Options) -> bool { let search_text = &options.search_text; let lines = content.lines(); @@ -193,7 +185,7 @@ fn find_text_files(options: &Options, dir_path: &Path) { }, &|p| { total_dir_count_cell.replace_with(|&mut c| c + 1); if let Some(p_str) = p.to_str() { - if (!options.scan_dot_git) && p_str.ends_with("/.git") { + if (!options.scan_dot_git_dir) && p_str.ends_with("/.git") { if options.verbose { clear_n_print_message(MessageType::INFO, &format!("Skip .git dir: {}", p_str)); } return false; } diff --git a/src/opt.rs b/src/opt.rs index 50d7116..df75ece 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -14,7 +14,7 @@ pub struct Options { pub filter_large_line: bool, pub large_line_size: String, pub parsed_large_line_size: u64, - pub scan_dot_git: bool, + pub scan_dot_git_dir: bool, pub skip_dot_dir: bool, pub skip_link_dir: bool, pub skip_target_dir: bool, @@ -39,7 +39,7 @@ impl Options { filter_large_line: false, large_line_size: String::from("10KB"), parsed_large_line_size: 0u64, - scan_dot_git: false, + scan_dot_git_dir: false, skip_dot_dir: false, skip_link_dir: false, skip_target_dir: false, @@ -62,7 +62,7 @@ impl Options { ap.refer(&mut self.ignore_case).add_option(&["-i", "--ignore-case"], StoreTrue, "Ignore case, default false"); ap.refer(&mut self.filter_large_line).add_option(&["--filter-large-line"], StoreTrue, "Filter large line"); ap.refer(&mut self.large_line_size).add_option(&["--large-line-size"], Store, "Large line, default 10KB"); - ap.refer(&mut self.scan_dot_git).add_option(&["--scan-dot-git"], StoreTrue, "Scan dot git"); + ap.refer(&mut self.scan_dot_git_dir).add_option(&["--scan-dot-git"], StoreTrue, "Scan dot git"); ap.refer(&mut self.skip_dot_dir).add_option(&["--skip-dot-dir"], StoreTrue, "Skipt dot dir [Text Mode]"); ap.refer(&mut self.skip_link_dir).add_option(&["--skip-link-dir"], StoreTrue, "Skip link dir"); ap.refer(&mut self.skip_target_dir).add_option(&["--skip-target-dir"], StoreTrue, "Skip target dir");