summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-06-02 14:20:27 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-06-02 14:20:27 +0200
commitb665c7cd4aa4ea900dc194a6ba5ad9de527f978c (patch)
tree34271a77a0ef1a3fc7c65b5aa8b2d0e3f6405afe
parent6dcfd93e8577c83192ed07d043eb4679987d5695 (diff)
Add support for filtering releases by package name and version
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/cli.rs19
-rw-r--r--src/commands/db.rs26
2 files changed, 44 insertions, 1 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 131eb41..71a2b67 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -365,6 +365,25 @@ pub fn cli<'a>() -> App<'a> {
.arg(arg_older_than_date("List only releases older than DATE"))
.arg(arg_newer_than_date("List only releases newer than DATE"))
+
+ .arg(Arg::new("package_name_regex")
+ .required(false)
+ .multiple(false)
+ .long("pkg")
+ .short('p')
+ .takes_value(true)
+ .value_name("REGEX")
+ .about("Limit search with package name matching REGEX")
+ )
+ .arg(Arg::new("package_version_constraint")
+ .required(false)
+ .multiple(false)
+ .long("version")
+ .short('v')
+ .takes_value(true)
+ .value_name("VERSION_CONSTRAINT")
+ .about("Limit search for package in version VERSION")
+ )
)
)
diff --git a/src/commands/db.rs b/src/commands/db.rs
index 24450f7..2e86954 100644
--- a/src/commands/db.rs
+++ b/src/commands/db.rs
@@ -14,6 +14,7 @@ use std::io::Write;
use std::path::PathBuf;
use std::process::Command;
use std::str::FromStr;
+use std::convert::TryFrom;
use anyhow::Context;
use anyhow::Error;
@@ -32,9 +33,11 @@ use log::info;
use log::trace;
use crate::config::Configuration;
-use crate::db::models;
use crate::db::DbConnectionConfig;
+use crate::db::models;
use crate::log::JobResult;
+use crate::package::PackageVersion;
+use crate::package::PackageVersionConstraint;
use crate::package::Script;
use crate::schema;
@@ -711,6 +714,17 @@ fn releases(conn_cfg: DbConnectionConfig<'_>, config: &Configuration, matches: &
query = query.filter(schema::releases::release_date.gt(date));
}
+ let package_name_regex_filter = matches.value_of("package_name_regex")
+ .map(crate::commands::util::mk_package_name_regex)
+ .transpose()
+ .context("Constructing package name regex")?;
+
+ let package_version_filter = matches.value_of("package_version_constraint")
+ .map(PackageVersionConstraint::try_from)
+ .transpose()
+ .context("Parsing package version constraint")
+ .context("A valid package version constraint looks like this: '=1.0.0'")?;
+
let data = query
.select({
let art = schema::artifacts::all_columns;
@@ -721,6 +735,16 @@ fn releases(conn_cfg: DbConnectionConfig<'_>, config: &Configuration, matches: &
})
.load::<(models::Artifact, models::Package, models::Release, models::ReleaseStore)>(&conn)?
.into_iter()
+ .filter(|(_, package, _, _)| {
+ package_name_regex_filter.as_ref()
+ .map(|regex| regex.captures(&package.name).is_some())
+ .unwrap_or(true)
+ })
+ .filter(|(_, package, _, _)| {
+ package_version_filter.as_ref()
+ .map(|verf| verf.matches(&PackageVersion::from(package.version.clone())))
+ .unwrap_or(true)
+ })
.filter_map(|(art, pack, rel, rstore)| {
let p = config.releases_directory().join(rstore.store_name).join(&art.path);