mirror of
https://github.com/jht5945/finding.git
synced 2025-12-29 22:20:05 +08:00
ref c
This commit is contained in:
42
src/main.rs
42
src/main.rs
@@ -6,12 +6,7 @@ extern crate rust_util;
|
|||||||
mod opt;
|
mod opt;
|
||||||
mod local_util;
|
mod local_util;
|
||||||
|
|
||||||
use std::{
|
use std::{ cell::RefCell, path::Path, time::SystemTime, };
|
||||||
cell::RefCell,
|
|
||||||
path::Path,
|
|
||||||
time::SystemTime,
|
|
||||||
};
|
|
||||||
|
|
||||||
use opt::*;
|
use opt::*;
|
||||||
use rust_util::{
|
use rust_util::{
|
||||||
iff,
|
iff,
|
||||||
@@ -27,15 +22,27 @@ const EMPTY: &str = "";
|
|||||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
const GIT_HASH: &str = env!("GIT_HASH");
|
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() {
|
fn print_version() {
|
||||||
println!(r#"finding {} - {}
|
println!(r#"finding {} - {}
|
||||||
Copyright (C) 2019 Hatter Jiang.
|
Copyright (C) 2019-2020 Hatter Jiang.
|
||||||
License MIT <https://opensource.org/licenses/MIT>
|
License MIT <https://opensource.org/licenses/MIT>
|
||||||
|
|
||||||
Written by Hatter Jiang"#, VERSION, &GIT_HASH[0..7]);
|
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_lastline(EMPTY);
|
||||||
print_message(mt, message);
|
print_message(mt, message);
|
||||||
}
|
}
|
||||||
@@ -47,12 +54,10 @@ fn find_huge_files(options: &Options, dir_path: &Path) {
|
|||||||
walk_dir(&dir_path, &|_, _| (/* do not process error */), &|p| {
|
walk_dir(&dir_path, &|_, _| (/* do not process error */), &|p| {
|
||||||
total_file_count_cell.replace_with(|&mut c| c + 1);
|
total_file_count_cell.replace_with(|&mut c| c + 1);
|
||||||
match p.metadata() {
|
match p.metadata() {
|
||||||
Err(err) => {
|
Err(err) => if options.verbose {
|
||||||
if options.verbose {
|
|
||||||
if let Some(p_str) = p.to_str() {
|
if let Some(p_str) = p.to_str() {
|
||||||
clear_n_print_message(MessageType::WARN, &format!("Read file {} meta failed: {}", p_str, err));
|
clear_n_print_message(MessageType::WARN, &format!("Read file {} meta failed: {}", p_str, err));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Ok(metadata) => {
|
Ok(metadata) => {
|
||||||
let len = metadata.len();
|
let len = metadata.len();
|
||||||
@@ -83,19 +88,6 @@ fn find_huge_files(options: &Options, dir_path: &Path) {
|
|||||||
get_display_size(huge_file_size_cell.into_inner() as i64)));
|
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 {
|
fn match_lines(tag: &str, content: &str, options: &Options) -> bool {
|
||||||
let search_text = &options.search_text;
|
let search_text = &options.search_text;
|
||||||
let lines = content.lines();
|
let lines = content.lines();
|
||||||
@@ -193,7 +185,7 @@ fn find_text_files(options: &Options, dir_path: &Path) {
|
|||||||
}, &|p| {
|
}, &|p| {
|
||||||
total_dir_count_cell.replace_with(|&mut c| c + 1);
|
total_dir_count_cell.replace_with(|&mut c| c + 1);
|
||||||
if let Some(p_str) = p.to_str() {
|
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)); }
|
if options.verbose { clear_n_print_message(MessageType::INFO, &format!("Skip .git dir: {}", p_str)); }
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ pub struct Options {
|
|||||||
pub filter_large_line: bool,
|
pub filter_large_line: bool,
|
||||||
pub large_line_size: String,
|
pub large_line_size: String,
|
||||||
pub parsed_large_line_size: u64,
|
pub parsed_large_line_size: u64,
|
||||||
pub scan_dot_git: bool,
|
pub scan_dot_git_dir: bool,
|
||||||
pub skip_dot_dir: bool,
|
pub skip_dot_dir: bool,
|
||||||
pub skip_link_dir: bool,
|
pub skip_link_dir: bool,
|
||||||
pub skip_target_dir: bool,
|
pub skip_target_dir: bool,
|
||||||
@@ -39,7 +39,7 @@ impl Options {
|
|||||||
filter_large_line: false,
|
filter_large_line: false,
|
||||||
large_line_size: String::from("10KB"),
|
large_line_size: String::from("10KB"),
|
||||||
parsed_large_line_size: 0u64,
|
parsed_large_line_size: 0u64,
|
||||||
scan_dot_git: false,
|
scan_dot_git_dir: false,
|
||||||
skip_dot_dir: false,
|
skip_dot_dir: false,
|
||||||
skip_link_dir: false,
|
skip_link_dir: false,
|
||||||
skip_target_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.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.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.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_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_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");
|
ap.refer(&mut self.skip_target_dir).add_option(&["--skip-target-dir"], StoreTrue, "Skip target dir");
|
||||||
|
|||||||
Reference in New Issue
Block a user