From dbcd101be62a4bc6bfbdad0b1f82de3020a43643 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 11 Nov 2020 12:36:45 +0100 Subject: Add optional version filtering for "source" subcommands Signed-off-by: Matthias Beyer --- examples/packages/example_1/config.toml | 1 + src/cli.rs | 14 ++++++++++++++ src/commands/source.rs | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/examples/packages/example_1/config.toml b/examples/packages/example_1/config.toml index 29e9465..25d5401 100644 --- a/examples/packages/example_1/config.toml +++ b/examples/packages/example_1/config.toml @@ -5,6 +5,7 @@ repository = "/tmp/butido_example_1" releases = "/tmp/butido-releases" staging = "/tmp/butido-staging" +source_cache = "/tmp/butido-sources" # #### # diff --git a/src/cli.rs b/src/cli.rs index da5efaa..796b921 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -289,6 +289,13 @@ pub fn cli<'a>() -> App<'a> { .value_name("PKG") .help("Verify the sources of this package (optional, if left out, all packages are checked)") ) + .arg(Arg::with_name("package_version") + .required(false) + .multiple(false) + .index(2) + .value_name("VERSION") + .help("Verify the sources of this package version (optional, if left out, all packages are checked)") + ) ) .subcommand(App::new("list-missing") .about("List packages where the source is missing") @@ -302,6 +309,13 @@ pub fn cli<'a>() -> App<'a> { .value_name("PKG") .help("Verify the sources of this package (optional, if left out, all packages are checked)") ) + .arg(Arg::with_name("package_version") + .required(false) + .multiple(false) + .index(2) + .value_name("VERSION") + .help("Verify the sources of this package version (optional, if left out, all packages are checked)") + ) ) ) diff --git a/src/commands/source.rs b/src/commands/source.rs index 25efcce..81dd98f 100644 --- a/src/commands/source.rs +++ b/src/commands/source.rs @@ -8,6 +8,7 @@ use clap_v3::ArgMatches; use crate::config::*; use crate::package::PackageName; +use crate::package::PackageVersionConstraint; use crate::repository::Repository; use crate::source::*; @@ -26,9 +27,11 @@ pub async fn verify<'a>(matches: &ArgMatches, config: &Configuration<'a>, repo: let source_cache_root = PathBuf::from(config.source_cache_root()); let sc = SourceCache::new(source_cache_root); let pname = matches.value_of("package_name").map(String::from).map(PackageName::from); + let pvers = matches.value_of("package_version").map(String::from).map(PackageVersionConstraint::new).transpose()?; 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)) .map(|p| { let source = sc.source_for(p); async move { @@ -73,9 +76,11 @@ pub async fn url<'a>(matches: &ArgMatches, config: &Configuration<'a>, repo: Rep let mut outlock = out.lock(); let pname = matches.value_of("package_name").map(String::from).map(PackageName::from); + let pvers = matches.value_of("package_version").map(String::from).map(PackageVersionConstraint::new).transpose()?; 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)) .map(|p| writeln!(outlock, "{} {} -> {}", p.name(), p.version(), p.source().url()).map_err(Error::from)) .collect() } -- cgit v1.2.3