diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-08-16 16:26:29 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-08-16 17:02:46 +0200 |
commit | 524fd6ca6f1ec8827c4c45177c709c3261ad47c5 (patch) | |
tree | cb02fed35b35b30b8f9a5cd8ef3d6cff6d60fac4 | |
parent | 2d4945938be440411e43c3440a368df0f70e5810 (diff) |
Add option to verify packages by name regex
This patch adds a feature so that we can verify sources for all packages
matching a regex.
For example
butido source verify --matching "perl5.34.0-.*"
for verifying all packages where their name matches "perl5.34.0-.*".
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r-- | src/cli.rs | 14 | ||||
-rw-r--r-- | src/commands/source.rs | 19 |
2 files changed, 28 insertions, 5 deletions
@@ -795,6 +795,20 @@ pub fn cli<'a>() -> App<'a> { .value_name("VERSION") .about("Verify the sources of this package version (optional, if left out, all packages are checked)") ) + + .arg(Arg::new("matching") + .required(false) + .multiple(false) + .long("matching") + .takes_value(true) + .value_name("REGEX") + .about("Verify all packages where the package name matches REGEX") + ) + + .group(ArgGroup::new("verify-one-or-many") + .args(&["package_name", "matching"]) + .required(true) + ) ) .subcommand(App::new("list-missing") .version(crate_version!()) diff --git a/src/commands/source.rs b/src/commands/source.rs index 52a0534..334bd2a 100644 --- a/src/commands/source.rs +++ b/src/commands/source.rs @@ -66,14 +66,23 @@ pub async fn verify( .map(PackageVersionConstraint::try_from) .transpose()?; + let matching_regexp = matches.value_of("matching") + .map(crate::commands::util::mk_package_name_regex) + .transpose()?; + let packages = repo .packages() - .filter(|p| pname.as_ref().map(|n| p.name() == n).unwrap_or(true)) .filter(|p| { - pvers - .as_ref() - .map(|v| v.matches(p.version())) - .unwrap_or(true) + match (pname.as_ref(), pvers.as_ref(), matching_regexp.as_ref()) { + (None, None, None) => true, + (Some(pname), None, None) => p.name() == pname, + (Some(pname), Some(vers), None) => p.name() == pname && vers.matches(p.version()), + (None, None, Some(regex)) => regex.is_match(p.name()), + + (_, _, _) => { + panic!("This should not be possible, either we select packages by name and (optionally) version, or by regex.") + }, + } }) .inspect(|p| trace!("Found for verification: {} {}", p.name(), p.version())); |