Skip to content

Commit

Permalink
added -i flag (case insensitive)
Browse files Browse the repository at this point in the history
  • Loading branch information
QpxDesign committed Jul 24, 2024
1 parent 831fff2 commit 5b82f22
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[package]
name = "webgrep"
version = "0.3.2"
version = "0.3.3"
edition = "2021"
license = "MIT"
description = "grep the web: a full-browser-spec search-focused ultra-simple way to read the web without having to leave the terminal"
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ async fn main() {
let num_urls = text_elements.keys().len();
let mut re = Regex::new(".*").unwrap();
if args.search.is_some() {
re = Regex::new(&args.search.unwrap()).unwrap();
if args.insensitive.is_some() && args.insensitive.unwrap() == true {
re = Regex::new(&("(?i)".to_owned() + &args.search.unwrap())).unwrap();
} else {
re = Regex::new(&args.search.unwrap()).unwrap();
}
}
for (link, texts) in text_elements.into_iter() {
let mut printed_texts: HashMap<String, bool> = HashMap::new();
Expand Down
3 changes: 3 additions & 0 deletions src/structs/Args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub struct ArgParser {
#[arg(short, long)]
pub recursive: Option<i8>,

#[arg(short, long, action=ArgAction::SetTrue)]
pub insensitive: Option<bool>,

#[arg(short = 'o', long = "samehost", action=ArgAction::SetTrue)]
pub samehost: Option<bool>,

Expand Down
6 changes: 6 additions & 0 deletions tests/test_cases.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ name = "Search/Basic"
run_type = "output"
cmd = "../target/release/webgrep https://quinnpatwardhan.com/aboutme Ravens -c"
expect = "die-hard"

[[test_cases]]
name = "Search/Insensitive"
run_type = "lines_count"
cmd = "../target/release/webgrep https://google.com dark -i"
expect = "3"

0 comments on commit 5b82f22

Please sign in to comment.