1
0
Mirror von https://github.com/Chaoscaot/schemsearch synchronisiert 2024-11-19 10:20:08 +01:00

Add Output Limit

Dieser Commit ist enthalten in:
Chaoscaot 2023-04-05 02:43:28 +02:00
Ursprung e7c1fd1ef7
Commit 2a112ac49c

Datei anzeigen

@ -150,6 +150,15 @@ fn main() {
.default_value("0") .default_value("0")
.value_parser(|s: &str| s.parse::<u16>().map_err(|e| e.to_string())) .value_parser(|s: &str| s.parse::<u16>().map_err(|e| e.to_string()))
) )
.arg(
Arg::new("limit")
.help("The maximum number of matches to return [0 = Unlimited]")
.short('l')
.long("limit")
.action(ArgAction::Set)
.default_value("50")
.value_parser(|s: &str| s.parse::<usize>().map_err(|e| e.to_string())),
)
.about("Searches for a pattern in a schematic") .about("Searches for a pattern in a schematic")
.bin_name("schemsearch"); .bin_name("schemsearch");
@ -264,6 +273,8 @@ fn main() {
bar.set_draw_target(ProgressDrawTarget::term_like(Box::new(MaschineStdErr { size: term_size }))) bar.set_draw_target(ProgressDrawTarget::term_like(Box::new(MaschineStdErr { size: term_size })))
} }
let max_matching = *matches.get_one::<usize>("limit").expect("Could not get max-matching");
let matches: Vec<SearchResult> = schematics.par_iter().progress_with(bar).map(|schem| { let matches: Vec<SearchResult> = schematics.par_iter().progress_with(bar).map(|schem| {
match schem { match schem {
SchematicSupplierType::PATH(schem) => { SchematicSupplierType::PATH(schem) => {
@ -300,13 +311,19 @@ fn main() {
} }
}).collect(); }).collect();
for matching in matches { let mut matches_count = 0;
'outer: for matching in matches {
let schem_name = matching.name; let schem_name = matching.name;
let matching = matching.matches; let matching = matching.matches;
for x in matching { for x in matching {
for out in &mut output { for out in &mut output {
write!(out.1, "{}", out.0.found_match(&schem_name, x)).unwrap(); write!(out.1, "{}", out.0.found_match(&schem_name, x)).unwrap();
} }
matches_count += 1;
if max_matching != 0 && matches_count >= max_matching {
break 'outer;
}
} }
} }