summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-08-16 16:26:29 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-08-16 16:26:31 +0200
commit7b32e20b96758f9e65cf78443520890214fdc2cb (patch)
tree6c9bcf138c141306c77b1beac5a081c3a24d4e53
parent2d4945938be440411e43c3440a368df0f70e5810 (diff)
Add option to download packages by name regex
This patch adds a feature so that we can download sources for all packages matching a regex. For example butido source download --matching "perl5.34.0-.*" for downloading all packages where their name matches "perl5.34.0-.*". Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/cli.rs14
-rw-r--r--src/commands/source.rs19
2 files changed, 28 insertions, 5 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 0da6745..2f58a6d 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -841,6 +841,20 @@ pub fn cli<'a>() -> App<'a> {
.long("force")
.about("Overwrite existing cache entry")
)
+
+ .arg(Arg::new("matching")
+ .required(false)
+ .multiple(false)
+ .long("matching")
+ .takes_value(true)
+ .value_name("REGEX")
+ .about("Download all packages matching a regex with their name")
+ )
+
+ .group(ArgGroup::new("download-one-or-many")
+ .args(&["package_name", "matching"])
+ .required(true)
+ )
)
.subcommand(App::new("of")
.version(crate_version!())
diff --git a/src/commands/source.rs b/src/commands/source.rs
index 52a0534..df3217f 100644
--- a/src/commands/source.rs
+++ b/src/commands/source.rs
@@ -285,14 +285,23 @@ pub async fn download(
mp
};
+ let matching_regexp = matches.value_of("matching")
+ .map(crate::commands::util::mk_package_name_regex)
+ .transpose()?;
+
let r = 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.")
+ },
+ }
})
.map(|p| {
sc.sources_for(p).into_iter().map(|source| {