Skip to content

Commit

Permalink
Add count only output for search results
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfrishkorn committed Sep 9, 2023
1 parent 975cf5f commit 3e24d85
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ fn main() -> Result<(), Box<dyn Error>> {
.num_args(1)
.action(ArgAction::Append),
)
.arg(
Arg::new("count")
.help("print match count only (no excerpts)")
.short('c')
.num_args(0)
.required(false)
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("context")
.help("number of surrounding context words displayed")
Expand Down Expand Up @@ -716,7 +724,12 @@ fn main() -> Result<(), Box<dyn Error>> {
eprint!(" occurrences: {}", term_match_count);
eprintln!();

// check to see if results are present
// exit if only counts are requested
if sub_matches.get_flag("count") {
return Ok(());
}

// exit if no results are present
if search_results.items.is_empty() {
return Ok(());
}
Expand Down

0 comments on commit 3e24d85

Please sign in to comment.