summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-01-23 09:12:20 +0100
committerMatthias Beyer <matthias.beyer@atos.net>2021-01-25 11:58:19 +0100
commitb702755720137b9b844c6580dfae9f2bd4c3fb83 (patch)
tree8c800434d9dc2c046a610bf71a711c583560858a /src
parent5783a654e4b5ab1a83cd5b23e83952bc79ddd1b0 (diff)
Refactor: Move package name regex building to helper function
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src')
-rw-r--r--src/commands/find_pkg.rs22
-rw-r--r--src/commands/util.rs17
2 files changed, 19 insertions, 20 deletions
diff --git a/src/commands/find_pkg.rs b/src/commands/find_pkg.rs
index 1d7f71b..e2f7b77 100644
--- a/src/commands/find_pkg.rs
+++ b/src/commands/find_pkg.rs
@@ -8,9 +8,7 @@
// SPDX-License-Identifier: EPL-2.0
//
-use anyhow::anyhow;
use anyhow::Context;
-use anyhow::Error;
use anyhow::Result;
use clap::ArgMatches;
use log::trace;
@@ -27,23 +25,9 @@ pub async fn find_pkg(
) -> Result<()> {
use std::io::Write;
- let package_name_regex = matches
- .value_of("package_name_regex")
- .map(regex::RegexBuilder::new)
- .map(|mut builder| {
- #[allow(clippy::identity_op)]
- builder.size_limit(1 * 1024 * 1024); // max size for the regex is 1MB. Should be enough for everyone
- builder
- .build()
- .with_context(|| {
- anyhow!(
- "Failed to build regex from '{}'",
- matches.value_of("package_name_regex").unwrap()
- )
- })
- .map_err(Error::from)
- })
- .unwrap()?; // safe by clap
+ let package_name_regex = crate::commands::util::mk_package_name_regex({
+ matches.value_of("package_name_regex").unwrap() // safe by clap
+ })?;
let package_version_constraint = matches
.value_of("package_version_constraint")
diff --git a/src/commands/util.rs b/src/commands/util.rs
index ec99d11..8862c05 100644
--- a/src/commands/util.rs
+++ b/src/commands/util.rs
@@ -10,10 +10,13 @@
use std::path::Path;
-use anyhow::anyhow;
+use anyhow::Error;
+use anyhow::Context;
use anyhow::Result;
+use anyhow::anyhow;
use clap::ArgMatches;
use log::{error, info, trace};
+use regex::Regex;
use tokio::stream::StreamExt;
use crate::config::*;
@@ -132,3 +135,15 @@ fn all_phases_available(pkg: &Package, available_phases: &[PhaseName]) -> Result
Ok(())
}
+
+pub fn mk_package_name_regex(regex: &str) -> Result<Regex> {
+ let mut builder = regex::RegexBuilder::new(regex);
+
+ #[allow(clippy::identity_op)]
+ builder.size_limit(1 * 1024 * 1024); // max size for the regex is 1MB. Should be enough for everyone
+
+ builder
+ .build()
+ .with_context(|| anyhow!("Failed to build regex from '{}'", regex))
+ .map_err(Error::from)
+}