mirror of
https://github.com/jht5945/finding.git
synced 2026-01-12 03:50:04 +08:00
Compare commits
2 Commits
5c628ff68a
...
c03ab9ff4c
| Author | SHA1 | Date | |
|---|---|---|---|
| c03ab9ff4c | |||
| 1d079d1d88 |
28
src/main.rs
28
src/main.rs
@@ -26,12 +26,11 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
|
|||||||
const GIT_HASH: &str = env!("GIT_HASH");
|
const GIT_HASH: &str = env!("GIT_HASH");
|
||||||
|
|
||||||
fn print_version() {
|
fn print_version() {
|
||||||
print!(r#"finding {} - {}
|
println!(r#"finding {} - {}
|
||||||
Copyright (C) 2019 Hatter Jiang.
|
Copyright (C) 2019 Hatter Jiang.
|
||||||
License MIT <https://opensource.org/licenses/MIT>
|
License MIT <https://opensource.org/licenses/MIT>
|
||||||
|
|
||||||
Written by Hatter Jiang
|
Written by Hatter Jiang"#, VERSION, &GIT_HASH[0..7]);
|
||||||
"#, VERSION, &GIT_HASH[0..7]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_huge_files(options: &Options, dir_path: &Path) {
|
fn find_huge_files(options: &Options, dir_path: &Path) {
|
||||||
@@ -43,10 +42,9 @@ fn find_huge_files(options: &Options, dir_path: &Path) {
|
|||||||
match p.metadata() {
|
match p.metadata() {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if options.verbose {
|
if options.verbose {
|
||||||
let p_str = p.to_str();
|
if let Some(p_str) = p.to_str() {
|
||||||
if p_str.is_some() {
|
|
||||||
print_lastline("");
|
print_lastline("");
|
||||||
print_message(MessageType::WARN, &format!("Read file {} meta failed: {}", p_str.unwrap(), err));
|
print_message(MessageType::WARN, &format!("Read file {} meta failed: {}", p_str, err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -105,7 +103,7 @@ impl MatchLine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn match_lines(tag: &str, content: &String, 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();
|
||||||
let mut match_lines_vec = vec![];
|
let mut match_lines_vec = vec![];
|
||||||
@@ -127,7 +125,7 @@ fn match_lines(tag: &str, content: &String, options: &Options) -> bool {
|
|||||||
false => ln.contains(the_search_text),
|
false => ln.contains(the_search_text),
|
||||||
};
|
};
|
||||||
let mut matches_line_content = true;
|
let mut matches_line_content = true;
|
||||||
if options.filter_line_content.len() > 0 {
|
if !options.filter_line_content.is_empty(){
|
||||||
if ! ln.contains(options.filter_line_content.as_str()) {
|
if ! ln.contains(options.filter_line_content.as_str()) {
|
||||||
matches_line_content = false;
|
matches_line_content = false;
|
||||||
}
|
}
|
||||||
@@ -139,7 +137,7 @@ fn match_lines(tag: &str, content: &String, options: &Options) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut matches_any = false;
|
let mut matches_any = false;
|
||||||
if match_lines_vec.len() > 0 {
|
if !match_lines_vec.is_empty() {
|
||||||
print_lastline("");
|
print_lastline("");
|
||||||
print_message(MessageType::OK, &format!("Find in {}:", tag));
|
print_message(MessageType::OK, &format!("Find in {}:", tag));
|
||||||
for i in 0..match_lines_vec.len() {
|
for i in 0..match_lines_vec.len() {
|
||||||
@@ -164,7 +162,7 @@ fn match_lines(tag: &str, content: &String, options: &Options) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn find_text_files(options: &Options, dir_path: &Path) {
|
fn find_text_files(options: &Options, dir_path: &Path) {
|
||||||
if options.search_text.len() < 1 {
|
if options.search_text.is_empty() {
|
||||||
print_message(MessageType::ERROR, "Param search_text cannot be empty.");
|
print_message(MessageType::ERROR, "Param search_text cannot be empty.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -174,7 +172,7 @@ fn find_text_files(options: &Options, dir_path: &Path) {
|
|||||||
let file_exts = match options.file_ext.as_str() {
|
let file_exts = match options.file_ext.as_str() {
|
||||||
"" => vec![],
|
"" => vec![],
|
||||||
ext => {
|
ext => {
|
||||||
ext.split(",").map(|s| s.trim()).filter(|s| s.len() > 0).map(|s| String::from(".") + s).collect()
|
ext.split(',').map(|s| s.trim()).filter(|s| !s.is_empty()).map(|s| String::from(".") + s).collect()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let total_file_count_cell = RefCell::new(0u64);
|
let total_file_count_cell = RefCell::new(0u64);
|
||||||
@@ -188,10 +186,10 @@ fn find_text_files(options: &Options, dir_path: &Path) {
|
|||||||
None => return,
|
None => return,
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
};
|
};
|
||||||
if file_exts.len() > 0 {
|
if !file_exts.is_empty() {
|
||||||
let mut file_ext_matches = false;
|
let mut file_ext_matches = false;
|
||||||
for i in 0..file_exts.len() {
|
for file_ext in &file_exts {
|
||||||
if p_str.to_lowercase().ends_with(&file_exts[i]) {
|
if p_str.to_lowercase().ends_with(file_ext) {
|
||||||
file_ext_matches = true;
|
file_ext_matches = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -200,7 +198,7 @@ fn find_text_files(options: &Options, dir_path: &Path) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if options.filter_file_name.len() > 0 {
|
if !options.filter_file_name.is_empty() {
|
||||||
if ! p_str.contains(options.filter_file_name.as_str()) {
|
if ! p_str.contains(options.filter_file_name.as_str()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user