mirror of
https://github.com/jht5945/finding.git
synced 2025-12-27 21:20:05 +08:00
add --filter-line-content
This commit is contained in:
@@ -120,7 +120,13 @@ fn match_lines(tag: &str, content: &String, options: &Options) -> bool {
|
||||
true => ln.to_lowercase().contains(the_search_text),
|
||||
false => ln.contains(the_search_text),
|
||||
};
|
||||
if matches {
|
||||
let mut matches_line_content = true;
|
||||
if options.filter_line_content.len() > 0 {
|
||||
if ! ln.contains(options.filter_line_content.as_str()) {
|
||||
matches_line_content = false;
|
||||
}
|
||||
}
|
||||
if matches && matches_line_content {
|
||||
match_lines_vec.push(MatchLine::new(l_no, ln.to_string()));
|
||||
}
|
||||
l_no += 1;
|
||||
|
||||
@@ -20,6 +20,7 @@ pub struct Options {
|
||||
pub skip_dot_dir: bool,
|
||||
pub skip_link_dir: bool,
|
||||
pub filter_file_name: String,
|
||||
pub filter_line_content: String,
|
||||
pub verbose: bool,
|
||||
pub search_text: String,
|
||||
}
|
||||
@@ -43,6 +44,7 @@ impl Options {
|
||||
skip_dot_dir: false,
|
||||
skip_link_dir: false,
|
||||
filter_file_name: String::new(),
|
||||
filter_line_content: String::new(),
|
||||
verbose: false,
|
||||
search_text: String::new(),
|
||||
}
|
||||
@@ -64,6 +66,7 @@ impl Options {
|
||||
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.filter_file_name).add_option(&["--filter-file-name"], Store, "Filter file name [Text Mode]");
|
||||
ap.refer(&mut self.filter_line_content).add_option(&["--filter-line-content"], Store, "Filter line content [Text Mode]");
|
||||
ap.refer(&mut self.version).add_option(&["-v", "--version"], StoreTrue, "Print version");
|
||||
ap.refer(&mut self.verbose).add_option(&["--verbose"], StoreTrue, "Verbose");
|
||||
ap.refer(&mut self.search_text).add_argument("SEARCH TEXT", Store, "Search text");
|
||||
|
||||
Reference in New Issue
Block a user