blob: b6c26a5e950e3cf5328a900ebe5fc6287ee86a30 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
use anyhow::Error;
use anyhow::Result;
use clap::ArgMatches;
use crate::config::Configuration;
use crate::package::Package;
use crate::repository::Repository;
pub async fn find_pkg<'a>(matches: &ArgMatches, config: &Configuration<'a>, repo: Repository) -> Result<()> {
use filters::filter::Filter;
use std::io::Write;
let package_filter = {
let regex = matches
.value_of("package_name_regex")
.map(regex::RegexBuilder::new)
.map(|mut builder| {
builder.size_limit(1 * 1024 * 1024); // max size for the regex is 1MB. Should be enough for everyone
builder.build()
.map_err(Error::from)
})
.unwrap()?; // safe by clap
move |p: &Package| -> bool {
regex.captures(p.name()).is_some()
}
};
let iter = repo.packages()
.filter(|package| package_filter.filter(package))
.inspect(|pkg| trace!("Found package: {:?}", pkg));
let out = std::io::stdout();
let mut outlock = out.lock();
if matches.is_present("terse") {
for p in iter {
writeln!(outlock, "{} {}", p.name(), p.version())?;
}
Ok(())
} else {
let format = config.package_print_format();
crate::ui::print_packages(&mut outlock,
format,
iter,
true,
true,
true,
true)
}
}
|